使用 Nodejs 通过 SMTP 协议发信
// load nodemailer as follows// npm install nodemailer --savevar nodemailer = require('nodemailer');// create reusable transporter object using SMTP transportvar transporter = nodemailer.createTransport({"host": "smtpdm.aliyun.com","port": 25,//"secureConnection": true, // use SSL, the port is 465"auth": {"user": 'username@userdomain', // user name"pass": 'xxxxxxx' // password}});// NB! No need to recreate the transporter object. You can use// the same transporter object for all e-mails// setup e-mail data with unicode symbolsvar mailOptions = {from: 'NickName<username@userdomain>', // sender address mailfrom must be same with the userto: 'x@x.com, xx@xx.com', // list of receiverscc:'haha<xxx@xxx.com>', // copy for receiversbcc:'haha<xxxx@xxxx.com>', // secret copy for receiverssubject: 'Hello', // Subject linetext: 'Hello world', // plaintext bodyreplyTo:'xxxxx@xxxxx.com',//custom reply addresshtml:'<b>Hello world</b><img src="cid:01" style="width:200px;height:auto">', // html bodyattachments: [{filename: 'text0.txt',content: 'hello world!'},{filename: 'text1.txt',path: './app.js'},{filename:'test.JPG',path:'./Desert.jpg',cid:'01'}],};// send mail with defined transport objecttransporter.sendMail(mailOptions, function(error, info){if(error){return console.log(error);}console.log('Message sent: ' + info.response);});
该文章对您有帮助吗?