相关文章推荐
一身肌肉的眼镜  ·  Spring ...·  5 月前    · 
玩足球的铅笔  ·  java ...·  1 年前    · 
胆小的鼠标  ·  UIScrollView+Masonry ...·  1 年前    · 
忐忑的爆米花  ·  python - ...·  1 年前    · 

最近实现使用公司内部邮箱发送邮件功能,发送给本公司邮箱时没有问题,但是给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引起的。

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

<bean id="mail" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<span style="white-space:pre">	</span><property name="host" value="${mail.smtp.host}" />
	<property name="port" value="${mail.smtp.port}" />
	<property name="username" value="${mail.user}" />
	<property name="password" value="${mail.password}" />
	 <property name="javaMailProperties">
	 <span style="white-space:pre">	</span><props>
	            <prop key="mail.transport.protocol">smtp</prop>
	            <prop key="mail.smtp.auth">true</prop>
	            <prop key="mail.debug">true</prop>
	           <prop key="mail.smtp.auth.mechanisms">NTLM</prop>
	     <prop key="mail.smtp.auth.ntlm.domain">xxxx-cn.com</prop>
	        </props>
	 </property>
</bean>

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

最近实现使用公司内部邮箱发送邮件功能,发送给本公司邮箱时没有问题,但是给QQ、163或sina等外部邮箱时一直出现错误:com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay此时的java mail 版本为1.4.1,升级到1.4.1之后这个问题就没有了。但是出现了错误:535 5.7.3 Authen 需要增加以下设置: properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.auth.mechanisms", "NTLM"); 就可以 解决 了,如果非WINDO...
解决 报错异常com.sun.mail.smtp.SMTPSendFailed Ex ception: 451 5.7 .3 STARTTLS is required to send mail
properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.auth.mechanisms", "NTLM"); 就可以 解决 了,如果非WINDOWS操作系统,需要将NTLM修改为digest方式;
SMTP 服务器要求安全连接或客户端未通过身份验证的各个 解决 方案(C#) 最近在做邮件发送接口 把遇到的问题和 解决 方法 告诉大家 希望对了解邮件的人有所帮助 原程序部分代码如下 //设置邮件信息 发件人地址、收件人地址、标题、主题 MailMessage mail = new MailMessage("xxxxxxx@sina.com", "zzzzzzz@sina....
当邮件使用SMTP协议 身份认证时,如果 出现 javax.mail. Authentication Failed Ex ception: 535 5.7 .3 Authentication unsu ccess ful . 则说明你的用户名与你的密码不正确导致验证失败! SMTP_AUTH_Fail_Response Message SMTP_AUTH_Fail_Response is defin
发送成功之后再控制台打印的内容1.先申请一个邮箱,然后开通pop3/smtp服务 这里我用的是网易的163邮箱 在开启POP3/SMTP服务的时候会让你输入一个授权码,这个授权码后面会用到. 2.代码的书写:@Test public void test JavaMail () throws Ex ception{
问题:生产邮件服务器邮件发送失败,异常如下: endcn.hutool. ex tra.mail.Mail Ex ception: Authentication Failed Ex ception: 535 5.7 .3 Authentication unsu ccess ful [HK0PR01CA0071.apcprd01.prod. ex change labs.com] DEBUG SMTP: Found ...