add send mail lib

This commit is contained in:
Jay
2017-06-05 18:25:48 +08:00
parent 69d560a21a
commit e094b97f10
6 changed files with 53 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
const nodemailer = require('nodemailer');
const config = require('../config.json');
module.exports = async(toMail, type = 'forgotpass', data = []) => {
let transporter = nodemailer.createTransport({
host: config.smtp.host,
port: config.smtp.port,
secure: config.smtp.secure, // secure:true for port 465, secure:false for port 587
auth: {
user: config.smtp.user,
pass: config.smtp.pass
}
});
// setup email data with unicode symbols
let mailOptions = {
from: config.smtp.sys_mail, // sender address
to: toMail, // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ?', // plain text body
html: '<b>Hello world ?</b>' // html body
};
return new Promise((resolve, reject) => {
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return reject(error);
}
// console.log('Message %s sent: %s', info.messageId, info.response);
return resolve(info);
});
});
}