nodejs nodemailer 使用

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

  

posted @ 2016-11-26 23:35  N1900  阅读(451)  评论(0编辑  收藏  举报