1,使用nodemailer
npm install nodemailer --save-dev
var nodemailer = require('nodemailer'); var internals = {}; internals.extend = function (o, n) { for (var p in n) { if (n.hasOwnProperty(p)) { o[p] = n[p]; } }; return o; }; var mailConfig = { service: 'qq', auth: { user: '8707***29@qq.com', pass: '********' } }; var mailOptions = { from: '870****9@qq.com', to: 'noahli@**.com', subject: '测试邮件', text: '测试邮件内容,请不要回复' }; internals.sendEmail = function (_config,_options, attachment) { mailConfig = internals.extend(mailConfig,_config); mailOptions = internals.extend(mailOptions,_options); //执行发送操作 var transporter = nodemailer.createTransport(mailConfig); transporter.sendMail(mailOptions, function (error, info) { if (error) { console.log("邮件发送错误:" + error); } else { console.log("邮件发送成功:" + info.response); } }); }; exports = module.exports = internals;
var email_tools = require('./service/email_server'); //发送邮箱配置 var config = { service: 'qq', auth: { user: '870****9@qq.com', pass: '******' } }; //收件箱配置 var options = { subject: "测试邮件", text: "我是邮件内容", to: "noahli@****.com", cc:"870***29@qq.com,51****78@qq.com", sender:"imdou8", attachments:[ { filename: 'app.js', //content: 'hello world!' path:"app.js" } ], html:{path:"tpl/index.html"} }; email_tools.sendEmail(config, options);
原文地址:http://blog.csdn.net/zimu002/article/details/45674339