var nodemailer = require(‘nodemailer‘)
var transporter = nodemailer.createTransport("SMTP", {
host: "smtp.126.com", // 主机
secureConnection : true, // 使用 SSL
port: 465, // SMTP 端口
auth: {
user: ‘[email protected]‘, //邮箱登录账号
pass:‘xxxxxxxxxxx‘ //使用邮箱里的授权码
}
});
var emailOptions = {
from : ‘xxx <[email protected]>‘,
to : ‘[email protected]‘,
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
原文地址:https://www.cnblogs.com/joyo-w/p/10753464.html
时间: 2024-10-15 11:59:41