发邮件的程序中 javax.mail.AuthenticationFailedException异常的处理

在Java中,通过程序发送QQ邮件时,报:javax.mail.AuthenticationFailedException

这是身份认证的错误,这个时候,需要从以下两方面着手(实际验证过的):

一、检查QQ邮箱或者别的邮箱是否开通了pop3/smtp服务,这个错误是认证失败,所以很有可能是没有开通pop3/smtp服务(需要开通,开通方式:https://blog.csdn.net/qq_35624642/article/details/72853055),我在这里犯了两个错误,一是mail.password我错写的是邮箱登录密码,正确的应该写为开通pop3/smtp服务时的验证码;二是没有开通pop3/smtp服务。


            final Properties props = new Properties();
 
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.host", "smtp.qq.com");
            //你自己的邮箱
            props.put("mail.user", "[email protected]"); 
            //你开启pop3/smtp时的验证码
            props.put("mail.password", "xxxxx");
            props.put("mail.smtp.port", "25");//465也可以的

 

例如实际的主要配置信息:

    
    
    
    
    
    
    
    
    
    
  

二、在用户名、密码都没有问题以及pop3/smtp服务也开通的情况下,还是报这个错误,先登录一下邮箱,测试是否能正常发送邮件。
有时候邮箱发送邮件过于频繁,可能被网站认为是恶意软件攻击,这个时候就需要定期去他们的网站登录一下,处理一下

三、还要注意一点,配置的时候一定要有:mail.smtp.auth=true
--------------------- 
信息正确后的跑出的日志信息如下且邮件可以正常发送:

DEBUG: JavaMail version 1.4.7
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.qq.com", port 465, isSSL false
220 smtp.qq.com Esmtp QQ Mail Server
DEBUG SMTP: connected to host "smtp.qq.com", port: 465

EHLO WINDOWS-LMPMR19.hundsun.com
250-smtp.qq.com
250-PIPELINING
250-SIZE 73400320
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN
250-MAILCOMPRESS
250 8BITMIME
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "73400320"
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
DEBUG SMTP: Found extension "MAILCOMPRESS", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
250 Ok
RCPT TO:
250 Ok
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   [email protected]
DATA
354 End data with .
From: [email protected]
To: [email protected]
Message-ID: <366691474.0.1541780188669.JavaMail.huangyong1@WINDOWS-LMPMR19>
Subject: =?UTF-8?B?5pyf6LSn5L+d6K+B6YeR57O757uf4oCU?=
 =?UTF-8?B?5Lit6YeR5omA6Leo6KGM6L2s6LSm5Lqk?=
 =?UTF-8?B?5piT5b6F56Gu6K6k77yB77yIUkVQRUFUICsy77yJ?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64

5bCK5pWs55qE5rGH5Liw6ZO26KGM5oiQ5ZGY77yM5oKo5aW977yBDQogICAgICAg5p2l6Ieq5pyf
6LSn5L+d6K+B6YeR57O757uf5Lqk5piT5o+Q6YaS77yB5pyJ5LiA56yU5Lit6YeR5omA6Leo6KGM
6L2s6LSm55qE5Lqk5piT77yI5rWB5rC05Y+3MjAxODExMDkxMTAzMTDvvInlvoXkurrlt6Xnoa7o
rqTvvIzor7flsL3lv6vmk43kvZzvvIENCg0KICAgICAgIOiwouiwou+8gQ0KDQrnpZ3lt6XkvZzp
obrliKnvvIENCjIwMTjlubQxMeaciDEw5pelDQo=
.
250 Ok: queued as 
QUIT
221 Bye
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.qq.com", port 465, isSSL false
220 smtp.qq.com Esmtp QQ Mail Server
DEBUG SMTP: connected to host "smtp.qq.com", port: 465
 

你可能感兴趣的:(javamail邮件程序)