QQ企业邮箱使用Java代码发送失败,错误DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NT

本文介绍了一种使用Java发送邮件时遇到的身份验证失败问题及解决方案。通过调整邮件发送配置,如开启安全协议并使用正确的SSL设置,成功解决了邮件无法发送的问题。

先前使用的代码:

String host = "xxx";
String from = "xxx";
String name = "xx";
String sender = "XXX";
String pwd = XXX";
String port = "465";
Properties prop = new Properties();
 //协议
prop.setProperty("mail.transport.protocol", "smtp");
 //服务器
prop.setProperty("mail.smtp.host", host);
        //端口
        prop.setProperty("mail.smtp.port", port + "");
        //使用smtp身份验证
        prop.setProperty("mail.smtp.auth", "true");
        //使用SSL,企业邮箱必需!
        //开启安全协议
        MailSSLSocketFactory sf = null;
        try {
            sf = new MailSSLSocketFactory();
            sf.setTrustAllHosts(true);
        } catch (GeneralSecurityException e1) {
            e1.printStackTrace();
        }
        prop.put("mail.smtp.ssl.enable", "true");
        prop.put("mail.smtp.ssl.socketFactory", sf);
      Session session = Session.getDefaultInstance(prop, new MyAuthenricator(name, pwd));
        session.setDebug(true);
// 建立邮件消息
MimeMessage mailMessage = new MimeMessage(session);

      Transport.send(mailMessage);

然而却出错了!

DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP:AUTH LOGIN failed

2017-05-04 16:41:35.589 ERROR com.rbao.east.task.TaskJobImpl - 182 -
sendEmail error mailMessage=javax.mail.internet.MimeMessage@39f840f5
javax.mail.AuthenticationFailedException: 535 Error: authentication failed, system busy


登陆授权失败!

弄了半天,将上述代码开启安全协议改了下:

prop.put("mail.smtp.starttls.enable", "true");
prop.put("mail.smtp.socketFactory.port", port);
prop.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

最终发送成功了!!!


我改了还是报错from 为1943564708@qq.com Adding recipients from trigger recipient list Successfully created MimeMessage Sending email to: 1943564708@qq.com DEBUG: getProvider() returning jakarta.mail.Provider[TRANSPORT,smtp,org.eclipse.angus.mail.smtp.SMTPTransport,Oracle] DEBUG SMTP: need username and password for authentication DEBUG SMTP: protocolConnect returning false, host=smtp.qq.com, user=我的4060TI$, password=<null> DEBUG SMTP: useEhlo true, useAuth true DEBUG SMTP: trying to connect to host "smtp.qq.com", port 465, isSSL false 220 newxmesmtplogicsvrszb20-0.qq.com XMail Esmtp QQ Mail Server. DEBUG SMTP: connected to host "smtp.qq.com", port: 465 EHLO host.docker.internal 250-newxmesmtplogicsvrszb20-0.qq.com 250-PIPELINING 250-SIZE 73400320 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 250-AUTH=LOGIN 250-MAILCOMPRESS 250-SMTPUTF8 250 8BITMIME DEBUG SMTP: Found extension "PIPELINING", arg "" DEBUG SMTP: Found extension "SIZE", arg "73400320" DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2" DEBUG SMTP: Found extension "AUTH=LOGIN", arg "" DEBUG SMTP: Found extension "MAILCOMPRESS", arg "" DEBUG SMTP: Found extension "SMTPUTF8", arg "" DEBUG SMTP: Found extension "8BITMIME", arg "" DEBUG SMTP: protocolConnect login, host=smtp.qq.com, user=weike1234, password=<non-null> DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2 DEBUG SMTP: Using mechanism LOGIN DEBUG SMTP: AUTH LOGIN command trace suppressed DEBUG SMTP: AUTH LOGIN failed AuthenticationFailedException message: 535 Login fail. Account is abnormal, service is not open, password is incorrect, login frequency limited, or system is busy. More information at https://help.mail.qq.com/detail/108/1023 Finished: SUCCESS
最新发布
11-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值