nodejs使用nodemailer 1.11.x版本发送邮件

 
  
 
  
var nodeMailer = require("nodemailer");

/*//0.7.1版本需要设置SMTP参数
var transport = nodeMailer.createTransport("SMTP", {
    host: "smtp.163.com",
    secureConnection: true, // use SSL
    port: 465, // port for secure SMTP
    auth: {
        user: "[email protected]",
        pass: "xxxxxx"
    }
});*/

var transport = nodeMailer.createTransport({
    service: "163",
    host: "smtp.163.com",
    secureConnection: true, // use SSL
    port: 465, // port for secure SMTP
    auth: {
        user: "[email protected]",
        pass: "xxxxxx"
    }
});

transport.sendMail({
    from : "[email protected]",
    to : "[email protected]",
    subject: "邮件主题",
    html : "这是封测试邮件",
    attachments: [
        // String attachment
        {
            filename: 'notes.txt',
            content: 'Some notes about this e-mail'
        }
    ]
}, function(error, response){
    if(error){
        console.log(error);
    }else{
        console.log("Message sent: " + response.message);
    }
    transport.close();
});

你可能感兴趣的:(nodejs)