NodeMailer
Nodejs發郵件組件Nodemailer
http://blog.fens.me/nodejs-em...
Node.js使用NodeMailer發送郵件
http://www.jianshu.com/p/ee20...
https://github.com/nodemailer...
https://nodemailer.com/about/
我們平常開發中 有時會遇到須要系統推送郵件給相關用戶(例如:註冊後發送激活郵箱等等),此時就須要用到NodeMailer;html
首先,去xxx雲/xxx雲/xxx雲 郵件推送【以a-l-i爲例】node
Nodemailer 是一個基於Node的郵件服務模塊。git
使用 Nodemailer 完成一個發郵件功能很是簡單,只需3步:github
1引入模塊ui
2建立 transportspa
3發送郵件code
/** * 郵箱服務 * add by wwj * 2017-02-15 23:47:16 */ var Promise = require("bluebird"); var i18n = require('i18n'); var config = require('config-lite'); //配置 var nodemailer = require('nodemailer'); //郵件服務 module.exports = { /** * 發送郵件 */ sendSystemEmail: function(opts) { return new Promise(function(resolve, reject) { //檢驗是否傳入郵件接收者 和郵件標題 和郵件內容 if (!opts.to || !opts.subject || !opts.html) { console.log(i18n.__('pleasePassParamsComplete')); reject(i18n.__('pleasePassParamsComplete')); return; } //從哪 opts.from = opts.from || '"博客系統" <' + config.email.service + '>'; //若是不是給管理員發 那麼抄送管理員 if(opts.to.indexOf(config.email.admin)<0){ //抄送 opts.cc = '"博客系統Admin" <'+ config.email.admin +'>'; } var transporter = nodemailer.createTransport({ pool: true, host: 'smtpdm.aliyun.com', //smtp.gmail.com port: 465, // 25 secure: true, // use SSL, 【不適用https能夠關閉】 auth: { user: config.email.service, pass: config.email.spassword, }, }); console.log(opts); transporter.sendMail(opts, function(error, info) { if (error) { console.log("郵件發送失敗啦"); console.log(error); reject('error'); return; } if (info) { console.log('Message sent success: ' + JSON.stringify(info)); } resolve('success'); }); }); }, };