用node實(shí)現(xiàn)郵件的發(fā)送

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);

});

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,506評(píng)論 19 139
  • ##### URL模塊 這個(gè)模塊可以幫助我們解析url地址,從里面提取很多有用的內(nèi)容供我們使用; 假設(shè)這是一個(gè)ur...
    浪流兒閱讀 3,030評(píng)論 0 2
  • 最近做個(gè)網(wǎng)站,用戶(hù)賬號(hào)申請(qǐng)了,管理員需要核實(shí),核實(shí)完畢才能激活用戶(hù)賬號(hào)。賬號(hào)核實(shí)后需要通知用戶(hù),于是采用了發(fā)送電子...
    乂千閱讀 1,778評(píng)論 0 4
  • afinalAfinal是一個(gè)android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,835評(píng)論 2 45
  • Node.js是目前非常火熱的技術(shù),但是它的誕生經(jīng)歷卻很奇特。 眾所周知,在Netscape設(shè)計(jì)出JavaScri...
    w_zhuan閱讀 3,720評(píng)論 2 41

友情鏈接更多精彩內(nèi)容