在nodejs程序中,我们可以使用nodemailer来发送邮件
1、安装nodemailer
npm install nodemailer
2、实现代码如下
<span style="font-size:18px;"><span style="font-size:18px;">var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
host: "smtp.qq.com",
auth: {
user: 'user@qq.com',
pass: 'userpass'
}
});</span>
transporter.sendMail({
from: 'user@qq.com',
to: 'addr@qq.com',
subject: 'hello',
html:'<p>这是邮箱确认链接<a href="http://www.baidu.com">http://www.baidu.com</a></p>'
}, function(err, response){
console.log('send mail err is ', err, response);
transporter.close();
});
收到的截图为:
当然,你也可以使用163的服务,改成smtp.163.com即可。
发送者的账号需要在邮箱设置中开启POP3/STMP服务。
nodemailer支持的邮件服务器列表官网有列,https://github.com/andris9/nodemailer-wellknown#supported-services ,不过163的邮件服务没找到。。。测试过后是可以用的。
本文介绍如何使用Node.js的nodemailer库来发送带有确认链接的HTML格式邮件。文章提供了详细的配置和代码示例,并说明了如何为不同的邮件服务商(如QQ邮箱和163邮箱)进行设置。
4万+

被折叠的 条评论
为什么被折叠?



