node

Node使用nodemailer发送邮件

2018-08-08  本文已影响69人  萤火虫de梦

1.配置

const mailTransport = nodemailer.createTransport({
    host : 'smtp.sina.com',
    secureConnection: true, // 使用SSL方式(安全方式,防止被窃取信息)
    auth : {
        user : '88888888@qq.com', //发送邮件的邮箱
        pass : 'xxxxxxxxxxxx' //第三方授权密码,POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务
    },
});

2.发送

//发送邮件
let sendmail = function(html){
    let option = {
   from:"88888888@qq.com",//发送邮件的邮箱
   to:"666666@qq.com,7777777@qq.com", //目标邮箱,多个邮箱用逗号隔开
   subject : '一封来自萤火虫de梦的邮件========',
   text : '一封来自萤火虫de梦的邮件+++++++',
   attachments : 
   [{
       filename: 'banner_1.jpg',   // 附件名
        path: 'https://www.lusheng521.com/wswifi/weidaozuji/banner_1.jpg',  // 附件路径
         cid : 'fn_01'  // _id 可被邮件使用
      }, {
      filename: 'banner_2.jpg', //附件名
      path: 'https://www.lusheng521.com/wswifi/weidaozuji/banner_1.jpg',  // 附件路径
       cid : 'fn_02'  // _id 可被邮件使用
    }]
 }
    option.html= html;
    transporter.sendMail(option, function(error, response){
        if(error){
            console.log("fail: " + error);
        }else{
            console.log("success: "+ response.message);
        }
    });
}
可用参数配置

3.调用发送邮件

sendmail ("<h1>图片:<img src='cid:fn_01'></h1>");

参考文献:https://nodemailer.com/about/

上一篇 下一篇

猜你喜欢

热点阅读