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

首頁 > 開發 > JS > 正文

簡單兩步使用node發送qq郵件的方法

2024-05-06 16:48:37
字體:
來源:轉載
供稿:網友

node發送郵件非常簡單,這里只做qq的演示,你可以舉一反三.

使用nodemailer包

let transporter = nodemailer.createTransport({ // 使用qq發送郵件 // 更多請查看支持列表:https://nodemailer.com/smtp/well-known/ service: 'qq', port: 465, // SMTP 端口 secureConnection: true, // 使用了 SSL auth: {  user: '751734566@qq.com',  // 這里密碼不是qq密碼,是你設置的smtp授權碼  // 獲取qq授權碼請看:https://jingyan.baidu.com/article/6079ad0eb14aaa28fe86db5a.html  pass: 'xxxxxxxx', }});

接下來我們設置我們到發送內容

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

如果我們想發一個稍微漂亮到郵件怎么辦?

我們可以使用html模板來實現

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

文檔參考

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

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平阴县| 兴隆县| 新绛县| 晋中市| 同心县| 临高县| 宁津县| 定南县| 调兵山市| 宜兰县| 上林县| 新昌县| 灵台县| 柳林县| 乐平市| 类乌齐县| 阿尔山市| 康定县| 栾川县| 花垣县| 临湘市| 定陶县| 睢宁县| 宝山区| 克山县| 新平| 定边县| 汤原县| 台江县| 樟树市| 新营市| 汝州市| 南江县| 栾城县| 尚志市| 常山县| 德令哈市| 元阳县| 廉江市| 黎平县| 阿拉善右旗|