nodejs發送郵件

nmp install nodemailer(若須要指定版本,使用@版本號便可)
html

var ndoemailer = require('nodemailer');

//開啓一個SMTP鏈接池
var smtpTransport = ndoemailer.createTransport('SMTP', {
      host: 'smtp.163.com', //主機
      secureConnection: true, //使用SSL
      port: 465, //SMTP接口
      auth: {
      	user: "user@163.com",
      	pass: "pass"
      }
});

//設置郵件內容
var mailOptions = {
	from: "user@163.com", //發件地址
	to: "to@qq.com",   //收件列表,多個用逗號分割
	subject: "Test SMTP SEND Email", //標題
	html: "<b>Hello World!</b>"   //html內容
}


//發送郵件
smtpTransport.sendMail(mailOptions, function(error, response){
      if(error) {
      	console.log(error);
      }else {
      	console.log("Message send:"+response.message);
      }
      smtpTransport.close();
});
相關文章
相關標籤/搜索