node(邮件发送特性)

1、安装 npm install nodemailer

https://github.com/andris9/Nodemailer

2、配置发邮件的账户开启SMTP功能;

3、程序样例如下:

var nodemailer = require('nodemailer');



var user = '[email protected]',

    password = 'XXXX';



// create reusable transporter object using SMTP transport

var transporter = nodemailer.createTransport({

    service: 'QQ',

    auth: {

        user: user,

        pass: password

    }

});



// setup e-mail data with unicode symbols

var mailOptions = {

    from: 'Fredric<' + user + '>', // sender address

    to: '[email protected]', // 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){

        console.log(error);

    }else{

        console.log('Message sent: ' + info.response);

    }

});

 

你可能感兴趣的:(node)