1 var nodemailer = require(‘nodemailer‘); 2 var transporter = nodemailer.createTransport({ 3 //https://github.com/andris9/nodemailer-wellknown#supported-services 支持列表 4 service: ‘qq‘, 5 port: 465, // SMTP 端口 6 secureConnection: true, // 使用 SSL 7 auth: { 8 user: ‘1466594176@qq.com‘, 9 //这里密码不是qq密码,是你设置的smtp密码 10 pass: ‘‘ 11 } 12 });
在qq邮箱中点击 “”“设置” =》“账号”
然后就可以发送邮件了
1 var mailOptions = { 2 from: ‘@qq.com‘, // 发件地址 3 to: ‘@qq.com‘, // 收件列表 4 subject: ‘查成绩啦‘, // 标题 5 //text和html两者只支持一种 6 text: ‘查成绩啦‘, // 标题 7 html: ‘<b>good luck for myself!</b>‘ // html 内容 8 }; 9 10 // send mail with defined transport object 11 transporter.sendMail(mailOptions, function(error, info) { 12 if (error) { 13 return console.log(error); 14 } 15 console.log(‘Message sent: ‘ + info.response); 16 17 });
其中有哪些邮件可以直接调用,可以查看对于的文档(https://nodemailer.com/smtp/well-known/)
附上查询成绩的js脚本 https://github.com/luguiqing/nodemailer
参考资料 https://www.cnblogs.com/pingfan1990/p/4864822.html