国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

簡(jiǎn)單兩步使用node發(fā)送qq郵件的方法

2019-11-19 12:03:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

node發(fā)送郵件非常簡(jiǎn)單,這里只做qq的演示,你可以舉一反三.

使用nodemailer包

let transporter = nodemailer.createTransport({ // 使用qq發(fā)送郵件 // 更多請(qǐng)查看支持列表: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)碼請(qǐng)看:https://jingyan.baidu.com/article/6079ad0eb14aaa28fe86db5a.html  pass: 'xxxxxxxx', }});

接下來(lái)我們?cè)O(shè)置我們到發(fā)送內(nèi)容

let mailOpt= { from: '"test" <xxxxxx@qq.com>', // 你到qq郵箱地址 to: 'xxxx@qq.com', // 接受人,可以群發(fā)填寫(xiě)多個(gè)逗號(hào)分隔 subject: 'Hello', // 主題名(郵件名) // 可以發(fā)送text或者h(yuǎn)tml格式,2選1 // text: 'Hello world?', // 純文本 html: '<b>Hello world?</b>' // html};

如果我們想發(fā)一個(gè)稍微漂亮到郵件怎么辦?

我們可以使用html模板來(lái)實(shí)現(xiàn)

const template = require('art-template');let html = template(__dirname + '/mail_temp.html', obj) // mail_temp.html為你想使用到頁(yè)面模板,obj為你的參數(shù)// 例如obj = {  name : 'test',  phone : '183xxxxxxxx',  time : new Date()}<section>  新用戶(hù):{{name}}({{phone}})于{{time}}進(jìn)行了注冊(cè).</section>所有準(zhǔn)備完成,讓我們發(fā)送郵件吧!// 執(zhí)行發(fā)送transporter.sendMail(mailOptions, (error, info) => { if (error) {  return console.log(error); } console.log('郵件已發(fā)送成功,郵件id: %s', info.messageId);});

文檔參考

nodemailer : https://www.npmjs.com/package/nodemailer

art-template : https://aui.github.io/art-template/zh-cn/docs/

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 乌拉特后旗| 保康县| 长垣县| 上蔡县| 景宁| 桐城市| 永仁县| 遂昌县| 柳州市| 江安县| 远安县| 建湖县| 右玉县| 吴堡县| 个旧市| 西华县| 莒南县| 旺苍县| 同德县| 新丰县| 漠河县| 杨浦区| 景德镇市| 扶绥县| 来宾市| 内乡县| 涿鹿县| 永安市| 建昌县| 霍州市| 平利县| 密山市| 合水县| 垫江县| 调兵山市| 淄博市| 南宫市| 商洛市| 宣化县| 龙海市| 饶阳县|