var nodemailer = require('nodemailer');
var opts = {
service: 'Gmail',
auth: {
pass: 'password'
}
}
var transporter = nodemailer.createTransport(opts);
exports.sendEmail = function (options) {
// console.log('=================================\n')
// from always uses opts auth user
var mailOptions = {
from: options.from,
sender: options.from,
subject: options.subject,
text: options.text,
html: options.html
// replyTo:options.replyTo,
// attachments: options.attachments
};
transporter.sendMail(mailOptions, function (error) {
if (error) {
console.log('Error occured');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
});
};
From a controller (setup variables to pass)
mtext = adjf + ' ' + adjl + " batch " + nextno + " data entries dated : " + dd + ' \r';
newdata = 'This is batch no ' + nextno + " data entries dated : " + dd + '\n You can adjust and entries through File Time Sheet option.</br> 0 values are null entries. </br>' + newdata;
var mailOptions = {
subject: adj,
text: mtext,
html: newdata + '</br>'
}
EmailService.sendEmail(mailOptions);
});
HTH
John