Nodejs使用mailer發送郵件
在實際應用中,有時需要服務器有特點的信息時及時的推送消息給你,而讓你有所準備和處理,項目中服務器的個數比較多,所以管理服務器集群也不是很方便,我就是每臺服務器上出現異常退出的時候都發送郵件到我的郵箱同時并重新啟動Nodejs服務器。
廢話不多說,實例上之:
首先,需要安裝一個發送郵件的模塊:
npm install mailer
然后在代碼中引入模塊:
var email = require("mailer");
最后使用模塊發送郵件:
email.send( { ssl: true, host: "smtp.exmail.qq.com",//發送 smtp.qq.com,接收 pop.qq.com domain: "[xxx.xxx.xxx.xxx]",//可以在瀏覽器中輸入 http://ip.qq.com/ 得到 to: "xxx@qq.com", from: "xxx@xxx.com", subject: "myemail test email", // reply_to: "xxx@xxx.com", body: "Hello! This is a test of the myemail.", authentication: "login", username: "xxx@xxx.com", password: "xxx", debug: false }, function (err, result) { if (err) { console.log("the err:" + err); response.write(JSON.stringify({ "提示信息": "發送失敗", "失敗原因": "數據異常" })); response.end(); } else { if (result) { console.log("發送成功"); response.write(JSON.stringify({ "提示信息": "發送成功" })); response.end(); } else { response.write(JSON.stringify({ "提示信息": "發送失敗", "失敗原因": "數據異常" })); response.end(); } } } );
Nodejs這個模塊簡單易用,希望對你有所幫助。
代碼下載:http://download.csdn.net/detail/qxs965266509/8896463
希望可以幫助到大家,對你有幫助或者覺得值得借鑒的,可以在下方點個贊!謝謝!!!
如有轉載請著名來自http://blog.csdn.net/qxs965266509
本文由用戶 aiguang 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!