-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail.js
63 lines (55 loc) · 2.34 KB
/
email.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const config = require('./config.json')
const colors = require('./colors')
const nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: `${config["gmail-user"]}`,
pass: `${config["gmail-app-password"]}`
},
tls: {
rejectUnauthorized: false
}
});
/**
*
* @param {Email Message} message The raw JSON email message
*/
function send(message) {
console.log(`[${new Date().toLocaleString()}] ${colors.cyan}Sending email ${colors.black}${colors.bright}(${message.subject})${colors.r}`)
var mailOptions = {
from: `Synergy Mailer <${config["gmail-user"]}>`,
to: config["destination-emails"],
subject: message.subject,
text: `${message.messageText}\n—\nAdditional information\nFrom: ${message.from.contactDetails1} (${message.from.contactDetails2})\nSend Date Time: ${message.sendDateTimeFormattedLong}\nOrganization: ${message.from.organizationName}\nRead/Sent: ${message.readCount}/${message.personCount}\n—\nThis email was autogenerated by the StudentVue Mailer`,
html: `<body>
<div
style="display:none; max-height:0px; max-width:0px; opacity:0; overflow:hidden;">
You have a new StudentVue message! This message was generated from the StudentVue mail service.
</div>
<span>${message.messageText}</span>
<div>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />
Additional information<br />
From: ${message.from.contactDetails1} (${message.from.contactDetails2})<br />
Send Date Time: ${message.sendDateTimeFormattedLong}<br />
Organization: ${message.from.organizationName}<br />
Read/Sent: ${message.readCount}/${message.personCount}<br />—
<br />This email was autogenerated by the StudentVue Mailer<br />
</p>
</div>
</body>`
};
return new Promise(function (resolve, reject) {
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(`[${new Date().toLocaleString()}] ` + error);
reject()
} else {
console.log('Email sent: ' + info.response);
resolve()
}
})
})
}
module.exports = send;