Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用身份验证TLS配置SMTP服务器_Java_Spring Boot_Smtp_Jakarta Mail_Starttls - Fatal编程技术网

Java 使用身份验证TLS配置SMTP服务器

Java 使用身份验证TLS配置SMTP服务器,java,spring-boot,smtp,jakarta-mail,starttls,Java,Spring Boot,Smtp,Jakarta Mail,Starttls,我正在配置我的微服务,以便在事件发生时发送电子邮件(在身份验证模式下,使用TLS),但我尚未获得所需的结果。 这是我上下文中的bean: <bean id="microserviceMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="${mail.smtp.host:}" /> <p

我正在配置我的微服务,以便在事件发生时发送电子邮件(在身份验证模式下,使用TLS),但我尚未获得所需的结果。 这是我上下文中的bean:

<bean id="microserviceMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="${mail.smtp.host:}" />
        <property name="port" value="${mail.smtp.port:587}"/>
        <property name="username" value="${mail.smtp.username:}"></property>
        <property name="password" value="${mail.smtp.password:}"></property>
        <property name="javaMailProperties">
            <props>
                <prop key="mail.smtp.auth">${mail.smtp.auth:true}</prop>
                <prop key="mail.smtp.starttls.enable">${mail.smtp.starttls.enable:true}</prop>
                <prop key="mail.debug">${mail.smtp.debug:true}</prop>
                <prop key="mail.smtp.from">MicroService@localhost</prop>
            </props>
        </property>
    </bean>
我得到以下错误:

DEBUG SMTP: trying to connect to host "smtp.live.com", port 587, isSSL false
220 VI1PR04CA0076.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 9 Nov 2017 11:55:40 +0000
DEBUG SMTP: connected to host "smtp.live.com", port: 587

EHLO ES00201376.localhost.se
250-VI1PR04CA0076.outlook.office365.com Hello [195.235.15.200]
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
EHLO ES00201376.localhost.se
250-VI1PR04CA0076.outlook.office365.com Hello [195.235.15.200]
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=smtp.live.com, user=xxxxx@hotmail.com, 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 succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<MicroService@localhost>
250 2.1.0 Sender OK
RCPT TO:<xxxxx@yahoo.com>
250 2.1.5 Recipient OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   xxxxx@yahoo.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Date: Thu, 9 Nov 2017 12:55:42 +0100 (CET)
To: xxxxx@yahoo.com
Message-ID: <514152430.0.1510228542603@ES00201376.localhost.se>
Subject: Notification from MicroService
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:.... [Hostname=AM4PR02MB3236.eurprd02.prod.outlook.com]
DEBUG SMTP: got response code 554, with response: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:....[Hostname=AM4PR02MB3236.eurprd02.prod.outlook.com]

RSET
250 2.0.0 Resetting
DEBUG SMTP: MessagingException while sending, THROW: 
com.sun.mail.smtp.SMTPSendFailedException: 554 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:... [Hostname=AM4PR02MB3236.eurprd02.prod.outlook.com]

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2267)
我没有收到回复:

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 "smtp.gmail.com", port 587, isSSL false
最后,使用另一台服务器

mail.smtp.starttls.enable=true
mail.smtp.auth=true
mail.smtp.host=mail.cartograf.net
mail.smtp.port=587
mail.smtp.username=XXXX@cartograf.net
mail.smtp.password=XXXX
mail.smtp.protocol=smtp
mail.smtp.debug=true
mail.smtp.mail.from=MicroService@localhost
mail.smtp.mail.subject=alert
因此:

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.cartograf.net", port 587, isSSL false
220 homiemail-a21.g.dreamhost.com ESMTP
DEBUG SMTP: connected to host "mail.cartograf.net", port: 587

EHLO ES00201376.localhost.se
DEBUG SMTP: exception reading response, THROW: 
java.net.SocketTimeoutException: Read timed out

使用Hotmail时,问题可能是您没有使用有效的发件人地址。有了Gmail,我不知道你为什么不能连接。试试这个。对于您的另一台服务器,我不知道为什么服务器没有及时响应。也许它不喜欢你的本地主机名?谢谢,这很有帮助。我已经更改了Hotmail配置中的“from”字段,它可以正常工作。此字段必须与Hotmail的“用户名”字段相同,问题可能是您没有使用有效的发件人地址。有了Gmail,我不知道你为什么不能连接。试试这个。对于您的另一台服务器,我不知道为什么服务器没有及时响应。也许它不喜欢你的本地主机名?谢谢,这很有帮助。我已经更改了Hotmail配置中的“from”字段,它可以正常工作。此字段必须与“用户名”字段相同
mail.smtp.starttls.enable=true
mail.smtp.auth=true
mail.smtp.host=mail.cartograf.net
mail.smtp.port=587
mail.smtp.username=XXXX@cartograf.net
mail.smtp.password=XXXX
mail.smtp.protocol=smtp
mail.smtp.debug=true
mail.smtp.mail.from=MicroService@localhost
mail.smtp.mail.subject=alert
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.cartograf.net", port 587, isSSL false
220 homiemail-a21.g.dreamhost.com ESMTP
DEBUG SMTP: connected to host "mail.cartograf.net", port: 587

EHLO ES00201376.localhost.se
DEBUG SMTP: exception reading response, THROW: 
java.net.SocketTimeoutException: Read timed out