const nodemailer = require('nodemailer');
const mailConfig = require('./server/config/mail');
// create reusable transporter object using the default SMTP transport
const transporter = nodemailer.createTransport({
host: 'smtp.zoho.com',
port: '465',
secure: true, // true for 465, false for other ports
auth: {
user: mailConfig.sender_mail, // generated ethereal user
pass: process.env.password, // generated ethereal password
},
});
const send = (to, content, subject, sender) => {
return new Promise((resolve, reject) => {
if (!content) return reject(new Error('fail because mail content was empty'));
const options = {
from: `${sender}<${mailConfig.sender_mail}>`,
to,
subject,
text: '', // plain text body
html: content, // html body
};
return transporter.sendMail(options, (error, info) => {
if (error) return reject(error);
return resolve(info);
});
});
};
send(
'aa@aa.aa',
'content',
'subject',
'sender');