Skip to content

Instantly share code, notes, and snippets.

@davidDuymelinck
Created October 20, 2014 07:14
Show Gist options
  • Save davidDuymelinck/cb370dab135b8b1b4c42 to your computer and use it in GitHub Desktop.
Save davidDuymelinck/cb370dab135b8b1b4c42 to your computer and use it in GitHub Desktop.
Newsletter.prototype.send = function send(){
var self = this,
mailCount = 0,
mailMax = this.people.length;
// people, from, subject, text and html are set before sending the mails
_.forEach(this.people, function(to){
var mail = {
from: this.from,
to: to,
subject: this.subject,
text: this.text,
html: this.html
};
// transport is set before using config variables and the nodemailer createTransport function
this.transport.sendMail(mail, function(err, info){
if(err){
self.emit('mailFailed', err, mail);
}else{
self.emit('mailSent', info, mail);
}
mailCount++;
if(mailCount === mailMax){
self.emit('newsletterSent');
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment