NodeJs 实现qq邮箱对接
1、安装nodemailer
npm install nodemailer -s
2、导入nodemailer 并配置
var nodemailer = require('nodemailer');
var config = {
host: 'smtp.qq.com',//网易163邮箱 smtp.163.com
port: 465,//网易邮箱端口 25
auth: {
user: 'xxxxxxx@qq.com', //邮箱账号
pass: 'xxxxxxx' //邮箱的授权码
}
};
var transporter = nodemailer.createTransport(config);
4、写个发生方法
function send(mail){
transporter.sendMail(mail, function(error, info){
if(error) {
return console.log(error);
}
console.log('mail sent:', info.response);
});
};
5、发生文件格式
var mail = {
// 发件人
from: '邮件<xxxxx@qq.com>',
// 主题
subject: '联系我们',
// 收件人
to: 'xxxxxx@qq.com',
// 邮件内容,HTML格式
text: '测试' //文本格式,
html:'这是h5格式'
};
6、发送
send(mail);
7、获取授权码