NodeMailer使用QQ邮箱来发送邮件

NodeMailer是一个用Node写的代理发送邮件的一个库。

它默认的配置是用gmail,但是因为某些原因我们可以换成别的。

首先安装库,nodemailer,nodemailer-smtp-transport,nodemailer-wellknown
cnpm install nodemailer nodemailer-smtp-transport nodemailer-wellknown --save
然后配置你的邮箱和密码config.auth,然后填充mailOptions里的内容,然后执行index.js,然后邮件就发送成功了。

index.js


var  nodemailer = require("nodemailer");
var smtpTransport = require('nodemailer-smtp-transport');
var wellknown = require("nodemailer-wellknown");
var config = wellknown("QQ");

config.auth = {
    user:'@qqcom',
    pass:''
}


var transporter = nodemailer.createTransport(smtpTransport(config));

var mailOptions = {
    from:"name<@qq.com>",
    to:"[email protected]",
    subject:"test",
    text:"text plain",
    html:"
div content
" }; // send mail with defined transport object transporter.sendMail(mailOptions, function(error, info){ if(error){ return console.log(error); } console.log('Message sent: ' + info.response); });

你可能感兴趣的:(NodeMailer使用QQ邮箱来发送邮件)