如何利用nodejs自動定時傳送郵件提醒(超實用)
阿新 • • 發佈:2020-12-01
需要先安裝外掛
npm install Nodemailer --save
index.js
global.SG = { nodemailer: require("nodemailer")//傳送郵件需要的服務 };
sg.js
//傳送郵件引數:收件人(支援群發)、主題、正文(支援html格式)---------------------------------------- sendMail(to,subject,html) { //下面這幾個改成你自己的郵箱、暱稱和授權碼 const user = "[email protected]"; const name = "強哥"; const pass = "btwyxxsd***yqdcgeda";//授權碼在QQ郵箱設定-賬號-開啟服務:POP3/SMTP服務(詳情參考https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256) global.SG.nodemailer.createTransport({host: "smtp.qq.com",auth: {user,pass}}).sendMail({ from: `${name}<${user}>`,//傳送者,例如:"標題別名 <[email protected]>" to,//收件人郵箱,多個郵箱地址間用英文逗號隔開,例如:"[email protected],[email protected]" subject,//郵件主題 html//支援html },err => err && console.log("郵件傳送失敗: ",err)); },
呼叫
$g.sendMail("[email protected],[email protected]","日報傳送提醒(系統自動傳送請勿回覆)",`<h1>親,怎麼還不傳送日報呀?</h1><br>這是來自強哥的問候,實在不行訪問下我的部落格吧<a href="http://www.shuzhiqiang.com" rel="external nofollow" target="_blank">www.shuzhiqiang.com</a>`);//傳送郵件
收到的郵件提醒
郵件內容
到此這篇關於如何利用nodejs自動定時傳送郵件提醒的文章就介紹到這了,更多相關nodejs自動定時傳送郵件提醒內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!