這次帶給大家怎麼操作Node.js發送郵件,操作Node.js發送郵件的注意事項有哪些,下面就是實戰案例,一起來看一下。
var nodemailer = require("nodemailer"); var mailTitle='http://handsupowo.pl/:Releases HandsUp Info'; var child_process = require('child_process'); var fs= require('fs'); child_process.execFile('phantomjs',['HandsupInfo.js'],function (err, result) { console.log("download over"); }); setTimeout(function() { readFile(); }, 20000); function readFile() { console.log('--------ReadFile--------'); fs.readFile('DownLoadUrl.txt','utf-8',function(err,data){ if(err){ }else{ sendSSLMail(data); } }) } function sendSSLMail(mailContent){ var stransporter = nodemailer.createTransport({ host: '填mailhost', secureConnection: true, // use SSL port: 465, // port auth: { user: 'username', pass: 'userpwd' } }); function ssl(){ var mailOptions = { from: '"2017 New HandsUp Info" <SponsorChecker@intasect.co.jp>', to: '1598828268@qq.com', cc:'hellomusic1993@qq.com', subject: mailTitle, text: mailContent, attachments:[ { filename : 'HandsupInfo.png', path: 'HandsupInfo.png' }, { filename : 'HandsupInfo.html', path: 'HandsupInfo.html' },{ filename : 'DownLoadUrl.txt', path: 'DownLoadUrl.txt' } ] } return mailOptions; } stransporter.sendMail(ssl(), function(error, info){ if(error){ console.log(error); }else{ console.log('Message sent: ' + info.response); } }); }
相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!
推薦閱讀:
#以上是怎麼操作Node.js發送郵件的詳細內容。更多資訊請關注PHP中文網其他相關文章!