Created
November 3, 2015 03:10
-
-
Save zgotsch/72a1a27d79ede4f8b7db to your computer and use it in GitHub Desktop.
Fancy email with nodemailer
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
var nodemailer = require('nodemailer'); | |
var fs = require('fs'); | |
// create reusable transporter object using SMTP transport | |
var transporter = nodemailer.createTransport({ | |
service: 'Gmail', | |
auth: { | |
user: '[email protected]', | |
pass: 'yourpasswordhere' | |
} | |
}); | |
// 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: 'Zach\'s Node ✔ <[email protected]>', // sender address | |
to: '[email protected]', // list of receivers | |
subject: 'This is an important test email ✔', // Subject line | |
text: 'Hello world ✔', // plaintext body | |
html: '<div><p><b>Hello world ☃</b></p><img src="cid:poliwag" /></div>', // html body | |
attachments: [ | |
{ | |
filename: 'poliwag.jpg', | |
cid: 'poliwag', | |
content: fs.createReadStream('./poliwag.jpg'), | |
} | |
] | |
}; | |
// send mail with defined transport object | |
transporter.sendMail(mailOptions, function(error, info){ | |
if(error){ | |
return console.log(error); | |
} | |
console.log('Message sent: ' + info.response); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment