STARTTLS is required but host does not support STARTTLS

问题描述 Windows server上ok 转到Centos7 虚拟机下报下面异常

问题原因是VM 上hostname 配置出现问题

开启debug 模式 查看问题 
spring.mail.properties.mail.debug=true

一直在想是什么原因,分析底层源码 com.sun.mail.smtp.SMTPTransport

if (serverSocket instanceof SSLSocket) {
   logger.fine("STARTTLS requested but already using SSL");
} else if (supportsExtension("STARTTLS")) {
   startTLS();
   /*
    * Have to issue another EHLO to update list of extensions
    * supported, especially authentication mechanisms.
    * Don't know if this could ever fail, but we ignore
    * failure.
    */
   ehlo(getLocalHost());
} else if (requireStartTLS) {
   logger.fine("STARTTLS required but not supported");
   throw new MessagingException(
"STARTTLS is required but " +
"host does not support STARTTLS");
}

supportsExtension("STARTTLS")) --问题发生在这里

windows 下 debug 片段

250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS

Linux 下

250-DSN
250-ENHANCEDSTATUSCODES
250-XXXXXXXA

 

 

EHLO localhost vs EHLO 218.93.250.18 引起的问题

不能用localhost 通过 mail.smtp.localhost=192.168.11.191 设置

解决办法:指定587 端口

spring.mail.port=587

centos 7 环境

 

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 "mail.geoswift.com", port 25, isSSL false
220 *********************************************************************************************************
DEBUG SMTP: connected to host "mail.geoswift.com", port: 25


EHLO localhost
250-DM5PR11CA0009.outlook.office365.com Hello [223.197.243.245]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-XXXXXXXA
250-8BITMIME
250-BINARYMIME
250-XXXXXXXB
250 XXXXXXXC
DEBUG SMTP: Found extension "SIZE", arg "157286400"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "XXXXXXXA", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "XXXXXXXB", arg ""
DEBUG SMTP: Found extension "XXXXXXXC", arg ""
DEBUG SMTP: STARTTLS required but not supported



Caused by: javax.mail.MessagingException: STARTTLS is required but host does not support STARTTLS
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:734) ~[javax.mail-1.5.6.jar!/:1.5.6]
at javax.mail.Service.connect(Service.java:366) ~[javax.mail-1.5.6.jar!/:1.5.6]
at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:501) ~[spring-context-support-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:421) ~[spring-context-support-4.3.10.RELEASE.jar!/:4.3.10.RELEASE]
... 58 common frames omitted

windows 环境 ok


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 "mail.geoswift.com", port 25, isSSL false
220 HK2PR02CA0194.outlook.office365.com Microsoft ESMTP MAIL Service ready at Mon, 21 Aug 2017 06:42:38 +0000
DEBUG SMTP: connected to host "mail.geoswift.com", port: 25


EHLO WCNSHA136.geoswift.local
250-HK2PR02CA0194.outlook.office365.com Hello [58.246.207.66]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "157286400"
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 "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 SMTP server ready
2017-08-21 14:44:40.988  INFO 8040 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver      : Resolving eureka endpoints via configuration
2017-08-21 14:44:40.989  WARN 8040 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver      : Invalid eureka server URI: /; removing from the server pool
EHLO WCNSHA136.geoswift.local
250-HK2PR02CA0194.outlook.office365.com Hello [58.246.207.66]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-AUTH LOGIN XOAUTH2
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "157286400"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN XOAUTH2"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: protocolConnect login, host=mail.geoswift.com, user=bankgateway@geoswift.com, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2 
DEBUG SMTP: Using mechanism LOGIN


250 2.6.0 <29088363.2.1503297927858@WCNSHA136.xxxxx.local> [InternalId=30958124272040, Hostname=HK2PR02MB0451.apcprd02.prod.outlook.com] 7111 bytes in 0.424, 16.368 KB/sec Queued mail for delivery
DEBUG SMTP: message successfully delivered to mail server
QUIT
221 2.0.0 Service closing transmission channel

 

参考

https://stackoverflow.com/questions/22027274/javamail-sending-with-smtp-auth-false-error-invalid-addresses

 

The server is configured not to relay messages outside its domain. You can change the server configuration, or perhaps you just need to authenticate to the server.

 

开启debug 模式 查看问题 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值