Created
May 23, 2014 14:21
-
-
Save rogeruiz/a16587d923b97a0c450d to your computer and use it in GitHub Desktop.
Sending email via NodeJS. Docs are here: http://www.nodemailer.com/docs/usage-example
This file contains hidden or 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
var nodemailer = require("nodemailer"); | |
// create reusable transport method (opens pool of SMTP connections) | |
var smtpTransport = nodemailer.createTransport("SMTP",{ | |
host: "mail.gandi.net", // hostname | |
secureConnection: true, // use SSL | |
port: 465, // port for secure SMTP | |
auth: { | |
user: "email@address", | |
pass: "myPassword" | |
} | |
}); | |
// setup e-mail data with unicode symbols | |
var mailOptions = { | |
from: "Node Roger ✔ <[email protected]>", // sender address | |
to: "[email protected], [email protected]", // list of receivers | |
subject: "Hello ✔", // Subject line | |
text: "Hello world ✔", // plaintext body | |
html: "<b>Hello world ✔</b>" // html body | |
}; | |
// send mail with defined transport object | |
smtpTransport.sendMail(mailOptions, function(error, response){ | |
if(error){ | |
console.log(error); | |
}else{ | |
console.log("Message sent: " + response.message); | |
} | |
// if you don't want to use this transport object anymore, uncomment following line | |
smtpTransport.close(); // shut down the connection pool, no more messages | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment