1、安装nodemailer模块
npm install --save nodemailer
2、引入nodemailer模块
const nodemailer = require("nodemailer");
3、复制粘贴
const nodemailer = require("nodemailer");
async function main(){
let testAccount = await nodemailer.createTestAccount();
let transporter = nodemailer.createTransport({
host: "smtp.qq.com", //邮件服务器 这里使用qq的
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: "000000000@qq.com", // 发送者的邮箱地址
pass: "oooooooooo" // 发送者的邮箱授权码
}
});
let info = await transporter.sendMail({
from: 'xxxxxx@qq.com', // 发送者
to: "xxxxxxxx@163.com", // 接收者 多个使用逗号隔开
subject: "Hello ✔", // 邮件主题
text: "Hello world?", // 文件内容
html: "<b>Hello world?</b>" // html内容
});
console.log(info) //打印发送后返回的东西
}
main().catch(console.error);
说明:如何获得邮箱的授权码
https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256%27
好了,这一波妥妥的,绝逼能用