node.js使用nodemailer发送qq邮箱

首先需要开启QQ邮箱的SMTP/IMAP服务开启,获取授权码
开启教程:https://jingyan.baidu.com/article/3052f5a1fc747f97f31f86c5.html

使用npm命令下载nodemailer模块

js代码:

var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
    //配置发送者的邮箱服务器和登录信息
    service:'qq',//163、qq等
    auth:{
        user:'[email protected]',//邮箱
        pass:''//邮箱密码或授权码
    }
});
var mailOptions = {
    from:'[email protected]',//'"邮件显示名" <[email protected]>',
    to:'[email protected]',//接受者 //'[email protected],[email protected]'支持多个邮件
    subject:'',//主题名
    text:'',//文本
    html:`<h2>nodemailer基本使用</h2>`,//内容,
    //附件
    attachments:[
        {
            //当前目录下的文件
            filename:'',
            path:''
        },
        {
            //创建一个文件
            filename:',
            content:''
        }
    ]
}
transporter.sendMail(mailOptions,function(err,info){
    if(err){
        console.log(err);
        return;
    }
    console.log("发送成功");
});

猜你喜欢

转载自blog.csdn.net/weixin_39842528/article/details/124434410