使用nodemailer模块发送邮件

 

var nodemailer=require('nodemailer');


var smtpTransport = nodemailer.createTransport({
host: 'smtp.qq.com',//qq邮箱的发邮件服务器
port: 465,
secure: true, // use SSL
auth: {
user: 'youremail@qq.com',
pass: 'yourpassword'
}
});

var mailOptions = {
  from: "发件人邮箱",
  to: "收件人地址",
  subject: "node邮件",
  html:"<h2>邮件内容</h2>"
}


smtpTransport.sendMail(mailOptions, function(err, resp){
  if(err){
    console.log(err)
  }
console.log("发送成功")
  smtpTransport.close();//关闭连接池
});

 

 

这是一个简单的使用nodemailer模块实现发送邮件功能的demo,实际开发中需要配合其他模块完成诸如邮箱验证,找回密码等等功能;

关于该模块详细的用法可以参见:https://github.com/nodemailer/nodemailer

posted on 2016-04-09 18:09  风不息、  阅读(454)  评论(0编辑  收藏  举报

导航