Skip to content

Instantly share code, notes, and snippets.

@joeylin
Created August 6, 2014 16:08
Show Gist options
  • Save joeylin/311697505aa4b1051779 to your computer and use it in GitHub Desktop.
Save joeylin/311697505aa4b1051779 to your computer and use it in GitHub Desktop.
nodemail config
var nodemailer = require('nodemailer');
var config = require('../config/config.js');
// Create a SMTP transport object
var transport = nodemailer.createTransport("SMTP", {
service: config.email.service,
auth: {
user: config.email.user,
pass: config.email.pass
}
});
// Message object
var message = {
// sender info
from: 'Joeylin <[email protected]>',
to: '',
// subject of the message
subject: 'Thanks for registering',
headers: {
'X-Laziness-level': 1000
},
html: ''
};
console.log('SMTP configured');
module.exports = function(user, feedback) {
if (typeof user === 'undefined') {
return;
}
if (feedback) {
message.to = '[email protected]';
message.html = '<p>用户: ' + user.name + '</p>' +
'<p>邮箱: ' + user.email + '</p>' +
'<p>' + user.content + '</p>';
} else {
// Recipt list
message.to = user.email;
// HTML body
message.html = '<p>请点击以下链接来完成注册:</p>' +
'<a href=http://192.168.1.218:3000/register/validate?token=' + user.emailActiveCode.code + '>' +
'http://192.168.1.218:3000/register/validate?token=' + user.emailActiveCode.code + '</a>';
}
console.log('sending email');
transport.sendMail(message, function(err) {
if (err) {
console.log(err.message);
return;
}
console.log('Message sent successfully!');
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment