1.我選擇的是nodemailer這個(gè)模塊
2.安裝 npm install nodemailer --save?
3.使用方式
const nodemailer=require('nodemailer');
let transporter=nodemailer.createTransport({
? ? service:'qq',
? ? auth: {
? ? ? ? user:'506782828@qq.com',
? ? ? ? //QQ郵箱 -> 設(shè)置 -> 帳戶(hù) -> 開(kāi)啟服務(wù):POP3/SMTP服務(wù) 會(huì)收到驗(yàn)證碼
? ? ? ? pass:'xxxxxxxxxxxxxx'//授權(quán)碼,通過(guò)QQ獲取
? ? }
});
let mailOptions={
? ? from:'506782828@qq.com',// 發(fā)件人地址
? ? to:'506782828@qq.com',// 收件人地址? 自己發(fā)自己進(jìn)行測(cè)試
? ? subject:'標(biāo)題',// 標(biāo)題
? ? //text和html兩者只支持一種
? ? text:'Hello world !',// 標(biāo)題
? ? html:'<h1>Hello world !</h1>'// html 內(nèi)容
};
let sendMail = (mailOptions,cb)=>{
? ? transporter.sendMail(mailOptions,cb);
};
sendMail(mailOptions,(error,info)=>{
? ? if(error){
? ? ? ? console.log(error);
? ? }
? ? console.log("發(fā)送郵件成功",info);
});