npm install nodemailer@4.7.0 // 直接nodemailer已经不支持了
可以参考源网站给出的代码,我这里自己精简了一下
‘use strict‘; const nodemailer = require(‘nodemailer‘); // 创建发送邮件的请求对象 let transporter = nodemailer.createTransport({ host: ‘smtp.ethereal.email‘, port: 587, // 端口号 secure: false, auth: { user: testAccount.user, // 发送方邮箱地址 pass: testAccount.pass // smtp 验证码 } }); // 邮件信息 let mailObj = { from: ‘"Fred Foo ??" <foo@example.com>‘, // 发送方邮箱及标题 to: ‘bar@example.com, baz@example.com‘, // 对方邮箱地址 subject: ‘Hello ?‘, // text: ‘Hello world?‘, // 邮件内容 html: ‘<b>Hello world?</b>‘ // html格式 }; transporter.sendMail(mailObj);
进入 node_modules --> nodemailer -- > lib --> well-known --> server.json
以QQ邮箱为例,如果需要发送邮件的邮箱是QQ邮箱,则 ctrl+f 查找QQ,并修改对应的host、port和secure
同样以QQ邮箱为例
原文:https://www.cnblogs.com/kusaki/p/11801769.html