1.下載 模塊html
2. 編輯文件 node
var nodemailer = require('nodemailer'); var sendEmail = function(emailinfo,callback){ var nodemailer = require('nodemailer'); var mail = emailinfo.emailaddress; //檢測郵箱地址是否爲空 if (!mail) { callback("請輸入郵箱地址!"); }else{ //檢測郵箱地址是否符合規範 if (!mail.match()) { callback("郵箱地址不符合規範,請從新輸入!"); }else{ //郵件發送 var transporter = nodemailer.createTransport({ host: 'smtp.mxhichina.com', port: 25, service: 'smtp.mxhichina.com ', auth: { user: 'xxx@xx.com',//你的郵箱帳號 pass: 'XXXXXX'//你的郵箱密碼 } }); var mailOptions = { from: '阿澤 xxxx@xxxx.com', // sender address to:mail, // list of receivers subject: '測試郵件', // Subject line text: 'Nodejs之郵件發送', // plaintext body html:"<h2><a href='test.jiucaiyun.cn/jiucaiyunstatic/' >"+emailinfo.inputperson+"邀請您來報價("+emailinfo.inquirynum+"),請登陸採購平臺來報價!</a></h2>", attachments:[ { filename : 'a.jpg', path: 'http://img13.360buyimg.com/n0/jfs/t4642/55/3978388666/72688/c8b2dcf/59080db2N7ae9168e.jpg' } ] }; transporter.sendMail(mailOptions, function(error, info){ if(!error){ callback( "郵件發送成功,請注意查收!"); }else{ console.log(error); callback("郵件發送失敗,請稍後重試!"); } }); } } }
var emailinfo = {"emailaddress":"chengzeqi@163.com","inputperson":"成澤琦(chengzq)","inquirynum":"XJDD201901100001"}
sendEmail(emailinfo,function(result){
console.log(result)
})json
3. 在 nodemailer-wellknown 模塊下 的services.json 文件最後一行添加 阿里雲的SMTP地址配置測試
"aliyun":{ "host": "smtp.mxhichina.com", "port": 25, "secure": true }
4. 發送郵件ui
5. 查看郵件阿里雲