34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
|
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);
|
||
|
});
|
||
|
});
|
||
|
}
|