-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_mail.js
More file actions
34 lines (29 loc) · 1.07 KB
/
send_mail.js
File metadata and controls
34 lines (29 loc) · 1.07 KB
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
const nodemailer = require("nodemailer");
const config = require("./config");
async function sendMail(subject, content, recipients, html) {
let account = await nodemailer.createTestAccount();
let transporter = nodemailer.createTransport({
host: config.mailHost,
port: config.mailPort,
secure: true, // true for 465, false for other ports
auth: {
user: config.mailUser, // generated ethereal user
pass: config.mailPass // generated ethereal password
}
});
let mailOptions = {
from: `"${config.mailFrom}" <${config.mailFrom}>`, // sender address
to: recipients, // list of receivers, comma separate
subject: subject, // Subject line
text: content, // plain text body
html: html // html body
};
try {
let info = await transporter.sendMail(mailOptions);
console.log("Message sent: %s", info.messageId);
console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info));
} catch(e) {
console.log(e);
}
}
module.exports = sendMail;