码迷,mamicode.com
首页 > Web开发 > 详细

nodejs nodemailer 使用

时间:2016-11-27 06:42:51      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:transport   密码   ssl   hello   unicode   lin   host   error   erro   

index.js

const  nodemailer=require("nodemailer")
let sendEmail=function () {
    var transporter = nodemailer.createTransport({
        host: "smtp.qq.com",
        port: 465,
        secure: true, // use SSL
        auth: {
            user: ‘xxx@qq.com‘,
            pass: ‘密码‘
        }
    });

// setup e-mail data with unicode symbols
    var mailOptions = {
        from: ‘"Test ??" <xxxxxx@qq.com>‘, // sender address
        to: ‘xxxxxxx@qq.com‘, // list of receivers
        subject: ‘Hello ?‘, // Subject line
        text: ‘Hello world ??‘, // plaintext body
        html: ‘<b>Hello world ??</b>‘ // html body
    };

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

 test.js

var send=require("../src/index");
send.sendEmail();

运行

npm src/test

  

nodejs nodemailer 使用

标签:transport   密码   ssl   hello   unicode   lin   host   error   erro   

原文地址:http://www.cnblogs.com/Zoes/p/6105676.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!