Created
September 12, 2017 11:24
-
-
Save yubaoquan/608f6c3e936bc931609ac5777fb652d0 to your computer and use it in GitHub Desktop.
test node-mailer
This file contains hidden or 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
const nodemailer = require('nodemailer'); | |
const mailConfig = { | |
secure: true, | |
host: 'smtp.126.com', | |
port: 465, | |
auth: { | |
user: '[email protected]', // 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