-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-factor email script into re-useable function with callback. dwyl/a…
- Loading branch information
Showing
1 changed file
with
23 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
}) |