npm install nodemailer //这个模块不错,github上星也比较多,还经常有维护,但是坑也比较多
npm install emailjs --save
npm install nodemailer --save
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
//https://github.com/andris9/nodemailer-wellknown#supported-services 支持列表
service: 'qq',
port: 465, // SMTP 端口
secureConnection: true, // 使用 SSL
auth: {
user: '768065158@qq.com',
//这里密码不是qq密码,是你设置的smtp密码
pass: '*****'
}
});
// NB! No need to recreate the transporter object. You can use
// the same transporter object for all e-mails
// setup e-mail data with unicode symbols
var mailOptions = {
from: '768065158@qq.com', // 发件地址
to: '528779822@qq.com', // 收件列表
subject: 'Hello sir', // 标题
//text和html两者只支持一种
text: 'Hello world ?', // 标题
html: '<b>Hello world ?</b>' // html 内容
};
// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
npm install nodemailer-smtp-transport --save
var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
// 开启一个 SMTP 连接池
var transport = nodemailer.createTransport(smtpTransport({
host: "smtp.qq.com", // 主机
secure: true, // 使用 SSL
secureConnection: true, // 使用 SSL
port: 465, // SMTP 端口
auth: {
user: "gaolu19901228@qq.com", // 账号
pass: "******" // 密码
}
}));
// 设置邮件内容
var mailOptions = {
from: "768065158<768065158@qq.com>", // 发件地址
to: "528779822@qq.com", // 收件列表
subject: "Hello world", // 标题
text:"hello",
html: "<b>thanks a for visiting!</b> 世界,你好!" // html 内容
}
// 发送邮件
transport.sendMail(mailOptions, function(error, response) {
if (error) {
console.error(error);
} else {
console.log(response);
}
transport.close(); // 如果没用,关闭连接池
});
{ [AuthError: Invalid login - 454 Authentication failed, please open smtp flag first!]
name: 'AuthError',
data: '454 Authentication failed, please open smtp flag first!',
stage: 'auth' }
{ [SenderError: Mail from command failed - 501 mail from address must be same as authorization user]
name: 'SenderError',
data: '501 mail from address must be same as authorization user',
stage: 'mail' }
Invalid login - 535 Authentication failed
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有