Created
August 19, 2015 09:53
-
-
Save NikolayGalkin/c2bd1411318013b9f596 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
var nodemailer = require('nodemailer'); | |
// Create a SMTP transporter object | |
var transporter = nodemailer.createTransport({ | |
host: '127.0.0.1', | |
port: 2500, | |
secure: false, | |
debug: true | |
}); | |
console.log('SMTP Configured'); | |
// Message object | |
var message = { | |
from: 'Sender Name <sender@example.com>', | |
// Comma separated list of recipients | |
to: '"Receiver Name" <receiver@example.com>', | |
// Subject of the message | |
subject: 'Nodemailer is unicode friendly ✔', | |
headers: { | |
'X-Project': 'foo', | |
'X-User': 'butko' | |
}, | |
html: '<p><b>Hello</b> to myself <img src="cid:note@example.com"/></p>' + | |
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:note2@example.com"/></p>', | |
attachments: [ | |
{ | |
filename: 'image.png', | |
content: new Buffer('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' + | |
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' + | |
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', 'base64'), | |
cid: 'note@example.com' // should be as unique as possible | |
}, | |
{ | |
filename: 'image.png', | |
content: new Buffer('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' + | |
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' + | |
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', 'base64'), | |
cid: 'note2@example.com' // should be as unique as possible | |
} | |
] | |
}; | |
console.log('Sending Mail'); | |
transporter.sendMail(message, function(error, info) { | |
if (error) { | |
console.log('Error occurred'); | |
console.log(error.response); | |
return; | |
} | |
console.log('Message sent successfully!'); | |
console.log('Server responded with "%s"', info.response); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment