Skip to content

Instantly share code, notes, and snippets.

@NikolayGalkin
Created August 19, 2015 09:53
Show Gist options
  • Save NikolayGalkin/c2bd1411318013b9f596 to your computer and use it in GitHub Desktop.
Save NikolayGalkin/c2bd1411318013b9f596 to your computer and use it in GitHub Desktop.
'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