-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_email.js
30 lines (27 loc) · 871 Bytes
/
util_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
'use strict';
const curTime = require("./util_time");
const cfg = require("./config");
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
"host": cfg.email.host,
"port": cfg.email.port,
"secureConnection": cfg.email.ssl, // use SSL
"auth": {
"user": cfg.email.uid, // user name
"pass": cfg.email.pwd // password
}
});
exports.sendMail = async function (title, body, to) {
let mailOptions = {
from: cfg.email.from, // sender address mailfrom must be same with the user
to: to, // list of receivers
subject: title, // Subject line
text: body, // plaintext body
};
try {
let info = await transporter.sendMail(mailOptions);
console.log(curTime(), 'Message sent: ' + info.response);
} catch(err) {
console.log(err);
}
};