node.js使用nodemailer發(fā)送郵件實(shí)例
一、安裝 nodemailer
二、調(diào)用
// 開啟一個(gè) SMTP 連接池
var smtpTransport = nodemailer.createTransport("SMTP",{
host: "smtp.qq.com", // 主機(jī)
secureConnection: true, // 使用 SSL
port: 465, // SMTP 端口
auth: {
user: "xxxxxxxx@qq.com", // 賬號(hào)
pass: "xxxxxxxx" // 密碼
}
});
// 設(shè)置郵件內(nèi)容
var mailOptions = {
from: "Fred Foo <xxxxxxxx@qq.com>", // 發(fā)件地址
to: "2838890xx@qq.com, minimixx@126.com", // 收件列表
subject: "Hello world", // 標(biāo)題
html: "<b>thanks a for visiting!</b> 世界,你好!" // html 內(nèi)容
}
// 發(fā)送郵件
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
}else{
console.log("Message sent: " + response.message);
}
smtpTransport.close(); // 如果沒(méi)用,關(guān)閉連接池
});
三、常見錯(cuò)誤
{ [AuthError: Invalid login - 454 Authentication failed, please open smtp flag first!]
name: 'AuthError',
data: '454 Authentication failed, please open smtp flag first!',
stage: 'auth' }
錯(cuò)誤原因: 賬號(hào)未設(shè)置該服務(wù)
解決方案: QQ郵箱 -> 設(shè)置 -> 帳戶 -> 開啟服務(wù):POP3/SMTP服務(wù)
{ [SenderError: Mail from command failed - 501 mail from address must be same as authorization user]
name: 'SenderError',
data: '501 mail from address must be same as authorization user',
stage: 'mail' }
錯(cuò)誤原因: 發(fā)件賬號(hào)與認(rèn)證賬號(hào)不同
- nodejs實(shí)現(xiàn)發(fā)送郵箱驗(yàn)證碼功能
- node.js模擬實(shí)現(xiàn)自動(dòng)發(fā)送郵件驗(yàn)證碼
- 如何利用node實(shí)現(xiàn)發(fā)送QQ郵箱驗(yàn)證碼
- Nodejs 發(fā)送Post請(qǐng)求功能(發(fā)短信驗(yàn)證碼例子)
- Node.js使用第三方插件nodemailer實(shí)現(xiàn)郵件發(fā)送示例
- Node使用Nodemailer發(fā)送郵件的方法實(shí)現(xiàn)
- nodejs模塊nodemailer基本使用-郵件發(fā)送示例(支持附件)
- Node.js使用NodeMailer發(fā)送郵件實(shí)例代碼
- 基于Node.js實(shí)現(xiàn)nodemailer郵件發(fā)送
- node 使用 nodemailer工具發(fā)送驗(yàn)證碼到郵箱
相關(guān)文章
JavaScript實(shí)現(xiàn)隨機(jī)五位數(shù)驗(yàn)證碼
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)隨機(jī)五位數(shù)驗(yàn)證碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-09-09
JavaScript中變量提升和函數(shù)提升實(shí)例詳解
這篇文章主要給大家介紹了關(guān)于JavaScript中變量提升和函數(shù)提升的相關(guān)資料,以及JS變量提升和函數(shù)提升的順序,文中給出了詳細(xì)的介紹,需要的朋友可以參考下2021-07-07
JS實(shí)現(xiàn)pasteHTML兼容ie,firefox,chrome的方法
這篇文章主要介紹了JS實(shí)現(xiàn)pasteHTML兼容ie,firefox,chrome的方法,涉及javascript針對(duì)頁(yè)面元素的動(dòng)態(tài)操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06
微信小程序與h5的相互跳轉(zhuǎn)場(chǎng)景分析
這篇文章主要介紹了微信小程序與h5的相互跳轉(zhuǎn)場(chǎng)景分析,在微信小程序內(nèi)編寫webview文件,通過(guò)webview去跳轉(zhuǎn)h5,loadUrl為h5的地址,非嵌套,h5需要跳轉(zhuǎn)打開某個(gè)微信小程序,需要的朋友可以參考下2023-10-10
JS實(shí)現(xiàn)點(diǎn)擊按鈕可實(shí)現(xiàn)編輯功能
本文通過(guò)一段實(shí)例代碼給大家介紹了基于js實(shí)現(xiàn)點(diǎn)擊按鈕可編輯效果,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的的朋友參考下吧2018-07-07
javascript 自動(dòng)標(biāo)記來(lái)自搜索結(jié)果頁(yè)的關(guān)鍵字
使用javascript自動(dòng)標(biāo)記來(lái)自搜索結(jié)果頁(yè)的關(guān)鍵字的實(shí)現(xiàn)代碼。2010-01-01

