美文网首页
node 发送邮件

node 发送邮件

作者: 天天快乐520 | 来源:发表于2018-01-19 11:04 被阅读0次

只需四步

1.设置一个用于发送邮件的账户,这里以qq邮箱为例。登录你的qq邮箱》设置


QQ截图20180119105434.png

开启POP3/SMTP和IMAP/SMTP 服务。开启后你会得到,一个 POP3/SMTP密码.
2.安装nodemailer

npm install nodemailer --save

3.写代码 sendmail.js

let nodemailer = require('nodemailer');
const POP3_SMTP_PASS =  "ywrv*******xymfcebgg";

let transporter = nodemailer.createTransport({
    //https://github.com/andris9/nodemailer-wellknown#supported-services 支持列表
    service: 'qq',
    port: 465, // SMTP 端口
    secureConnection: true, // 使用 SSL
    auth: {
        //配置 POP3_SMTP 的账号
        user: '2502****5@qq.com',
        //这里密码不是qq密码,是你设置的smtp密码
        pass: POP3_SMTP_PASS
    }
});

// NB! No need to recreate the transporter object. You can use
// the same transporter object for all e-mails

// setup e-mail data with unicode symbols
let mailOptions = {
    from: '250****695@qq.com', // 发件地址
    to: '8****470@qq.com', // 收件列表
    subject: 'Hello sir', // 标题
    //text和html两者只支持一种
    //text: 'Hello world ?', // 标题
    html: '<b>Hello world ?</b> <a href="http://www.baidu.com">fasdf</a>' // html 内容
};

// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
    if(error){
        return console.log(error);
    }
    console.log('Message sent: ' + info.response);

});
  1. 执行
node sendmail.js

如果发送成功,麻烦给个喜欢或者赞!!!!

相关文章

网友评论

      本文标题:node 发送邮件

      本文链接:https://www.haomeiwen.com/subject/tulooxtx.html