nodemailer 使用qq的smtp 显示认证失败
发布于 9 年前 作者 icantunderstand 6353 次浏览 最后一次编辑是 8 年前 来自 问答

我使用gmail的服务总是显示连接tiemout 但是我能连上google 换成qq的smtp 下面是例子

var nodemailer = require("nodemailer");
// 开启一个 SMTP 连接池
var smtpTransport = nodemailer.createTransport('SMTP',{
  host: "smtp.qq.com", // 主机
  secureConnection: true, // 使用 SSL
  port: 465, // SMTP 端口
  auth: {
    user: "xxxxx@qq.com", // 账号
    pass: "xxxx" // 密码
  }
});
// 设置邮件内容
var mailOptions = {
  from: "Fred Foo <863863aa@qq.com>", // 发件地址
  to: "icantunderstand@yeah.net", // 收件列表
  subject: "Hello world", // 标题
  html: "<b>thanks a for visiting!</b> 世界,你好!" // html 内容
}
// 发送邮件
smtpTransport.sendMail(mailOptions, function(error, response){
  if(error){
    console.log(error);
  }else{
    console.log("Message sent: " + response.message);
  }
  smtpTransport.close(); // 如果没用,关闭连接池
});

老是显示认证失败 系统繁忙 我qq邮箱的smtp服务也开了 这个是什么问题呢 求各位大神解答下

7 回复

把错误信息帖一下,我貌似之前也出现过,后来换126邮箱就ok了,不知道腾讯邮箱是不是还有什么其他安全认证

QQ邮箱要开启 smtp ,还要设置二次认证密码,这个密码就是SMTP密码。

我试过用二次密码也失败

看看 DoraCMS 的写法,用的是qq邮箱,发送正常

sendEmail : function(key,obj,callBack){

        var emailTitle = "Hello";
        var emailSubject = "Hello";
        var emailContent = "Hello";
        var toEmail;

        if(key == settings.email_findPsd){
            toEmail = obj.email;
            var oldLink = obj.password +'$'+ obj.email +'$'+ settings.session_secret;
            var newLink = DbOpt.encrypt(oldLink,settings.encrypt_key);

            emailSubject = emailTitle = '['+settings.SITETITLE +'] 通过激活链接找回密码';
            emailContent = siteFunc.setConfirmPassWordEmailTemp(obj.userName,newLink);
        }else if(key == settings.email_notice_contentMsg){
            emailSubject = emailTitle = '['+settings.SITETITLE +'] 用户留言提醒';
            emailContent = siteFunc.setNoticeToAdminEmailTemp(obj);
            toEmail = settings.site_email;
        }else if(key == settings.email_notice_user_contentMsg){
            emailSubject = emailTitle = '['+settings.SITETITLE +'] 有人给您留言啦';
            emailContent = siteFunc.setNoticeToUserEmailTemp(obj);
            toEmail = obj.replyAuthor.email;
        }else if(key == settings.email_notice_contentBug){
            emailSubject = emailTitle = '['+settings.SITETITLE +'] 有人给您提bug啦';
            emailContent = siteFunc.setBugToAdminEmailTemp(obj);
            toEmail = settings.site_email;
        }

//                发送邮件
        var transporter = nodemailer.createTransport({

            service: 'QQ',
            auth: {
                user: settings.site_email,
                pass: settings.site_email_psd
            }

        });

        var mailOptions = {
            from: settings.site_email, // sender address
            to: toEmail, // list of receivers
            subject: emailSubject, // Subject line
            text: emailTitle, // plaintext body
            html: emailContent // html body
        };

        transporter.sendMail(mailOptions, function(error, info){
            if(error){
                console.log('邮件发送失败:'+error);
                callBack(error);
            }else{
                console.log('Message sent: ' + info.response);
                callBack();
            }
        });


    }
	
	```
	
和上面兄弟说的一样,前提是qq邮箱要开启 smtp

@carlisliu 126邮箱的话 host 就是 smtp.126.com 对吗?

@doramart 我试一下这个 我的邮箱开启了smtp

@klesh 恩 刚才设置了2次认证密码 管用了 多谢

回到顶部