1、使用nodemailer模块
var nodemailer = require("nodemailer");
2、代码如下
exports.send_email = function(req,res) { //发件人信息设置 var smtpTransport = nodemailer.createTransport("SMTP",{ host: "smtp.163.com", auth: { user: "[email protected]",//账户 pass: "123456"//密码 } }); //邮件选项设置 var mailOptions = { from: "[email protected]", // 发件人地址 to: "[email protected],[email protected]", //多个收件人用,分隔 subject: "Node.js发送邮件测试", // 主题 html: "<b>我是HTML格式内容</b>" // html body } //发送 smtpTransport.sendMail(mailOptions, function(error, response){ if(error){ console.log(error); }else{ console.log("Message sent: " + response.message); } smtpTransport.close(); res.send(‘ok‘); }); }
时间: 2024-12-20 00:35:04