var nodemailer = require(“nodemailer”); var user = '*@qq.com’, pass = ‘';
var smtpTransport = nodemailer.createTransport("SMTP", {
host : ‘smtp.qq.com’,
auth: {
user: user,
pass: pass
}
});
smtpTransport.sendMail({
from : '@qq.com’
, to : '@163.com’
, subject : ‘Node.JS通过SMTP协议从QQ邮箱发送邮件’
, html : '这是一封测试邮件
'
}, function(err, res) {
console.log(err, res);
});
控制总是会报错 { [Error: connect EADDRNOTAVAIL] code: 'EADDRNOTAVAIL’, errno: 'EADDRNOTAVAIL’, syscall: ‘connect’ } undefined
请区分SSL端口和非SSL端口;
var smtpTransport = nodemailer.createTransport("SMTP",{ host: "smtp.163.com", secureConnection: true, // use SSL port: 465, // port for secure SMTP auth: { user: " ", pass: " " } });
qq邮箱的邮件发送: nodemailer.createTransport("SMTP", { host: 'smtp.qq.com’, secureConnection: true, port: 465, auth: { user: '[email protected]’, pass: ‘password’ } })
如果不能发的话,查看下邮箱的smtp等服务开了没.