Skip to content

Commit

Permalink
re-factor email script into re-useable function with callback. dwyl/a…
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Apr 16, 2015
1 parent 2eba028 commit eb00382
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions email.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,27 @@ var transporter = nodemailer.createTransport({
// NB! No need to recreate the transporter object. You can use
// the same transporter object for all e-mails

// setup e-mail data with unicode symbols
var mailOptions = {
from: '#dwyl do what you love! <[email protected]>', // sender address
to: '[email protected]', // list of receivers
subject: 'Welcome to dwyl!', // Subject line
text: textonly, // plaintext body
html: template
};
var email = function(person, callback){
var mailOptions = {
from: '#dwyl do what you love! <[email protected]>', // sender address
to: person.email, // list of receivers
subject: 'Welcome to dwyl!', // Subject line
text: textonly, // plaintext body
html: template
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
// console.log(error, info);
callback(error, info)
});

// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
}else{
console.log('Message sent: ' + info.response);
}
});
}

var person = {
email : '[email protected]',
name : 'FirstName'
}

email(person, function(error,info){
console.log(info);
})

0 comments on commit eb00382

Please sign in to comment.