JavaMail出现535 5.7.3 Authentication unsuccessful错误的解决方法

最近实现使用公司内部邮箱发送邮件功能,发送给本公司邮箱时没有问题,但是给QQ、163或sina等外部邮箱时一直出现错误:

com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay

此时的java mail 版本为1.4.1,升级到1.4.7之后这个问题就没有了。但是出现了错误:
535 5.7.3 Authentication unsuccessful
在邮箱配置文件中设置mail.debug为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: trying to connect to host "exchange.xxxxxxx.com.cn", port 25, isSSL false
220 excas1.logic-cn.com Microsoft ESMTP MAIL Service ready at Tue, 28 Apr 2015 18:44:53 +0800
DEBUG SMTP: connected to host "exchange.logicsolutions.com.cn", port: 25

EHLO xxx.xxx.xxx.xxx//ip地址
250-excas1.xxxx-cn.com Hello [xxx.xxx.xxx.xxx]
250-SIZE 37748736
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-X-ANONYMOUSTLS
250-AUTH NTLM
250-X-EXPS GSSAPI NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 XRDST
DEBUG SMTP: Found extension "SIZE", arg "37748736"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "X-ANONYMOUSTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "NTLM"
DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "XRDST", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: NTLM
DEBUG NTLM: type 1 message: 4E 54 4C 4D 53 53 50 00 01 00 00 00 03 A2 00 00 00 00 00 00 23 00 00 00 03 00 03 00 20 00 00 00 31 39 32 
DEBUG SMTP: AUTH NTLM command trace suppressed
DEBUG NTLM: type 3 message: 4E 54 4C 4D 53 53 50 00 03 00 00 00 18 00 18 00 86 00 00 00 18 00 18 00 9E 00 00 00 00 00 00 00 40 00 00 00 40 00 40 00 40 00 00 00 06 00 06 00 80 00 00 00 00 00 00 00 B6 00 00 00 01 82 00 00 72 00 65 00 63 00 72 00 75 00 69 00 74 00 69 00 6E 00 67 00 40 00 6C 00 6F 00 67 00 69 00 63 00 73 00 6F 00 6C 00 75 00 74 00 69 00 6F 00 6E 00 73 00 2E 00 63 00 6F 00 6D 00 2E 00 63 00 6E 00 31 00 39 00 32 00 83 BF 3A A6 03 EF 29 16 17 C7 7E 2A AF 63 C0 24 C7 D1 87 84 53 D1 16 DA 7D 9F D1 2D 63 E0 48 AD 9D 21 FA 53 E8 C9 72 16 A6 E6 33 9A 2B 9A C1 89 
DEBUG SMTP: AUTH NTLM failed
可见问题是由:AUTH NTLM failed引起的。


修改配置文件中的邮箱配置:

	
	
	
	
	 
	 
	 	
	            smtp
	            true
	            true
	           NTLM
	     xxxx-cn.com
	        
	 

需要注意的是username是登陆邮箱是的用户名而不是邮箱,password是登陆邮箱的密码,mail.smtp.auth.ntlm.domain是邮箱服务器的domain。



你可能感兴趣的:(项目开发)