Skip to content

Instantly share code, notes, and snippets.

@yubaoquan
Created September 12, 2017 11:24
Show Gist options
  • Save yubaoquan/608f6c3e936bc931609ac5777fb652d0 to your computer and use it in GitHub Desktop.
Save yubaoquan/608f6c3e936bc931609ac5777fb652d0 to your computer and use it in GitHub Desktop.
test node-mailer
const nodemailer = require('nodemailer');
const mailConfig = {
secure: true,
host: 'smtp.126.com',
port: 465,
auth: {
user: 'xxxxx@126.com', // your account and password
pass: 'xxxxx'
}
};
const transporter = nodemailer.createTransport(mailConfig);
function send(args) {
const mailOptions = {
from: mailConfig.auth.user,
to: args.to,
subject: args.subject || 'Hello ✔',
html: args.html || '<b>Hello world ?</b>',
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return log('send fail', error);
}
console.log('Message %s sent: %s', info.messageId, info.response);
});
}
send({
to: 'xxx', // another email
subject: 'test',
html: '<div>test</div>'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment