這篇文章主要介紹如何使用node發(fā)送qq郵件,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

使用nodemailer包
let transporter = nodemailer.createTransport({
// 使用qq發(fā)送郵件
// 更多請查看支持列表:https://nodemailer.com/smtp/well-known/
service: 'qq',
port: 465, // SMTP 端口
secureConnection: true, // 使用了 SSL
auth: {
user: '751734566@qq.com',
// 這里密碼不是qq密碼,是你設(shè)置的smtp授權(quán)碼
// 獲取qq授權(quán)碼請看:https://jingyan.baidu.com/article/6079ad0eb14aaa28fe86db5a.html
pass: 'xxxxxxxx',
}
});接下來我們設(shè)置我們到發(fā)送內(nèi)容
let mailOpt= {
from: '"test" <xxxxxx@qq.com>', // 你到qq郵箱地址
to: 'xxxx@qq.com', // 接受人,可以群發(fā)填寫多個逗號分隔
subject: 'Hello', // 主題名(郵件名)
// 可以發(fā)送text或者html格式,2選1
// text: 'Hello world?', // 純文本
html: '<b>Hello world?</b>' // html
};如果我們想發(fā)一個稍微漂亮到郵件怎么辦?
我們可以使用html模板來實現(xiàn)
const template = require('art-template');
let html = template(__dirname + '/mail_temp.html', obj) // mail_temp.html為你想使用到頁面模板,obj為你的參數(shù)
// 例如
obj = {
name : 'test',
phone : '183xxxxxxxx',
time : new Date()
}
<section>
新用戶:{{name}}({{phone}})于{{time}}進行了注冊.
</section>
所有準備完成,讓我們發(fā)送郵件吧!
// 執(zhí)行發(fā)送
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('郵件已發(fā)送成功,郵件id: %s', info.messageId);
});以上是“如何使用node發(fā)送qq郵件”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)站題目:如何使用node發(fā)送qq郵件-創(chuàng)新互聯(lián)
標題鏈接:http://www.chinadenli.net/article18/iehgp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、網(wǎng)頁設(shè)計公司、商城網(wǎng)站、微信小程序、移動網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容