I've written a node js module that sends emails. The module is a wrapper for the nodemailer module. When the callback of transporter.sendMail is executed, I want my wrapper function to return true if the email was sent, or false otherwise. How can I do this? Here's the code:
var nodemailer = require('nodemailer');
module.exports.sendEmail = function (mailerAddress, mailerPassword, to, subject, html) {
var transporter, mailOptions;
transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: mailerAddress,
pass: mailerPassword
}
});
mailOptions = {
from: mailerAddress,
to: to,
subject: subject,
html: html
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
return false;
}
else {
return true;
}
});
};