Node.js使用NodeMailer发送邮件

笑着哭i 提交于 2020-03-03 08:30:00

 

var nodemailer = require('nodemailer')

 

var transporter = nodemailer.createTransport("SMTP", {
host: "smtp.126.com", // 主机
secureConnection : true, // 使用 SSL
port: 465, // SMTP 端口
auth: {
user: 'xxxxxx@126.com', //邮箱登录账号
pass:'xxxxxxxxxxx' //使用邮箱里的授权码
}
});

 

var emailOptions = {
from : 'xxx <xxxxxx@126.com>',
to : 'xxxxxxxx@qq.com',
subject : 'test mail subject',
text : 'test mail text',
html : '<h1>test mail html</h1>'
}

 

transporter.sendMail(emailOptions, function(err, info) {
if(err){
return console.log(err);
}else{
console.log('Message sent: ' + info.message);
}
transporter.close(); // 如果没用,关闭连接池
});
 
参考: https://www.cnblogs.com/sharpest/p/8074923.html
 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!