gpt4 book ai didi

Java 应用程序无法从命令行发送电子邮件,从 Eclipse 可以

转载 作者:太空宇宙 更新时间:2023-11-03 13:38:10 25 4
gpt4 key购买 nike

我有一个使用 Spring JavaMailSenderImpl 的 Java 应用程序。当我在 Eclipse 下运行它时,它可以正常发送邮件,但是当我从 Windows 命令行运行它时,我得到:

Exception in thread "main" org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.net.SocketException: Connection reset. Failed messages: javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.net.SocketException: Connection reset; message exception details (1) are:
Failed message 1:
javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1907)

邮件发送者 bean 定义为:

    <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="xxx" />
<property name="username" value="xxx" />
<property name="password" value="xxx" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.debug">true</prop>
<prop key="mail.smtp.port">587</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.smtp.ssl.trust">xxx</prop>
</props>
</property>
</bean>

当我使用 -Djavax.net.debug=all 运行失败的应用程序时,我得到:

*** ClientHello, TLSv1
RandomCookie: GMT: 1444872267 bytes = { 11, 176, 76, 50, 109, 72, 37, 170, 87, 187, 17, 29, 131, 177, 0, 222, 129, 223, 21, 127, 165, 248, 122, 127, 39, 133, 190, 14 }
Session ID: {}
Cipher Suites: [TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, T
LS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
Compression Methods: { 0 }
Extension elliptic_curves, curve names: {secp256r1, sect163k1, sect163r2, secp192r1, secp224r1, sect233k1, sect233r1, sect283k1, sect283r1, secp384r1, sect409k1, sect409r1, secp521r1, sect571k1, sect571r1, secp160k1, secp160r1, secp160r2, sect163r1, secp192k1, sect193r1, sect193r2, secp224k1, sect23
9k1, secp256k1}
Extension ec_point_formats, formats: [uncompressed]
Extension server_name, server_name: [type=host_name (0), value= <cut>]
***
[write] MD5 and SHA1 hashes: len = 171
0000: 01 00 00 A7 03 01 56 1F 00 4B 0B B0 4C 32 6D 48 ......V..K..L2mH
0010: 25 AA 57 BB 11 1D 83 B1 00 DE 81 DF 15 7F A5 F8 %.W.............
0020: 7A 7F 27 85 BE 0E 00 00 1E C0 09 C0 13 00 2F C0 z.'.........../.
0030: 04 C0 0E 00 33 00 32 C0 08 C0 12 00 0A C0 03 C0 ....3.2.........
0040: 0D 00 16 00 13 00 FF 01 00 00 60 00 0A 00 34 00 ..........`...4.
0050: 32 00 17 00 01 00 03 00 13 00 15 00 06 00 07 00 2...............
0060: 09 00 0A 00 18 00 0B 00 0C 00 19 00 0D 00 0E 00 ................
0070: 0F 00 10 00 11 00 02 00 12 00 04 00 05 00 14 00 ................
0080: 08 00 16 00 0B 00 02 01 00 00 00 00 1E 00 1C 00 ................
<cut>
main, WRITE: TLSv1 Handshake, length = 171
[Raw write]: length = 176
0000: 16 03 01 00 AB 01 00 00 A7 03 01 56 1F 00 4B 0B ...........V..K.
0010: B0 4C 32 6D 48 25 AA 57 BB 11 1D 83 B1 00 DE 81 .L2mH%.W........
0020: DF 15 7F A5 F8 7A 7F 27 85 BE 0E 00 00 1E C0 09 .....z.'........
0030: C0 13 00 2F C0 04 C0 0E 00 33 00 32 C0 08 C0 12 .../.....3.2....
0040: 00 0A C0 03 C0 0D 00 16 00 13 00 FF 01 00 00 60 ...............`
0050: 00 0A 00 34 00 32 00 17 00 01 00 03 00 13 00 15 ...4.2..........
0060: 00 06 00 07 00 09 00 0A 00 18 00 0B 00 0C 00 19 ................
0070: 00 0D 00 0E 00 0F 00 10 00 11 00 02 00 12 00 04 ................
0080: 00 05 00 14 00 08 00 16 00 0B 00 02 01 00 00 00 ................
<cut>
main, handling exception: java.net.SocketException: Connection reset
main, SEND TLSv1.2 ALERT: fatal, description = unexpected_message
main, WRITE: TLSv1.2 Alert, length = 2
main, Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error
main, called closeSocket()
Exception in thread "main" org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.net.SocketException: Connection reset. Failed messages: javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.net.SocketException: Connection reset; message exception details (1) are:
Failed message 1:
javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
java.net.SocketException: Connection reset
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1907)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:666)

鉴于对 Client_Hello 没有响应,我假设输出消息被阻止,但我尝试暂时禁用 Windows 防火墙和 Avast 防病毒软件而不做任何更改。 (并不完全令人惊讶,因为 python 应用程序可以毫无问题地使用同一服务器发送邮件。)

Wireshark 跟踪似乎(我不是协议(protocol)专家...)显示来自主机的拒绝消息:

wireshark trace

查看 Client_Hellos,我在失败的密码套件中看到了一个小得多的密码套件列表: Failing Client_Hello

比成功者: OK Client_Hello

这可能是 Client_Hello 被拒绝的原因吗?

什么可能导致应用程序在从命令行运行时表现不同?

最佳答案

您似乎对使用端口 587 还是端口 465 感到困惑。试试 getting rid of all the socket factory settings看看是否有帮助。

关于Java 应用程序无法从命令行发送电子邮件,从 Eclipse 可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33138604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com