var transporter = nodemailer.createTransport({//v1.0 above do not use 'SMTP' as first param host: "smtp.xxx.xxx.com", port: 25, name:"xx.xx.com", tls: { rejectUnauthorized:false, }, auth: { user: user, pass: password } }); // setup e-mail data with unicode symbols var mailOptions = { date: new Date(), from: 'noreply@xxx.xxx.com', // sender address to: 'xxx@xxx.com, xxx@qq.com,', // list of receivers subject: title, // Subject line text:content, html: '<div>'+content.replace(/[ ]+/g,'<br />')+'</div>' // html body }; var msg = yield function(fn){ // send mail with defined transport object transporter.sendMail(mailOptions, function(error, info){ var msg=''; if(error){ msg = 'sendMail fail>>>'+error; } msg = 'Message sent: ' + (info&&info.response); transporter.close(); fn(error,msg); }); }
KOA 项目内,使用 co 框架扁平化回调函数
文档:
http://nodemailer.com/2-0-0-beta/setup-smtp/