• <tfoot id='1BZ7O'></tfoot>

    <small id='1BZ7O'></small><noframes id='1BZ7O'>

          <bdo id='1BZ7O'></bdo><ul id='1BZ7O'></ul>
      1. <legend id='1BZ7O'><style id='1BZ7O'><dir id='1BZ7O'><q id='1BZ7O'></q></dir></style></legend>

        <i id='1BZ7O'><tr id='1BZ7O'><dt id='1BZ7O'><q id='1BZ7O'><span id='1BZ7O'><b id='1BZ7O'><form id='1BZ7O'><ins id='1BZ7O'></ins><ul id='1BZ7O'></ul><sub id='1BZ7O'></sub></form><legend id='1BZ7O'></legend><bdo id='1BZ7O'><pre id='1BZ7O'><center id='1BZ7O'></center></pre></bdo></b><th id='1BZ7O'></th></span></q></dt></tr></i><div id='1BZ7O'><tfoot id='1BZ7O'></tfoot><dl id='1BZ7O'><fieldset id='1BZ7O'></fieldset></dl></div>

        无法使用 SMTP 发送电子邮件(获取 javax.mail.MessagingException:无法将套接字转换为

        时间:2023-10-14

          1. <tfoot id='H44sQ'></tfoot>

          2. <i id='H44sQ'><tr id='H44sQ'><dt id='H44sQ'><q id='H44sQ'><span id='H44sQ'><b id='H44sQ'><form id='H44sQ'><ins id='H44sQ'></ins><ul id='H44sQ'></ul><sub id='H44sQ'></sub></form><legend id='H44sQ'></legend><bdo id='H44sQ'><pre id='H44sQ'><center id='H44sQ'></center></pre></bdo></b><th id='H44sQ'></th></span></q></dt></tr></i><div id='H44sQ'><tfoot id='H44sQ'></tfoot><dl id='H44sQ'><fieldset id='H44sQ'></fieldset></dl></div>

              • <bdo id='H44sQ'></bdo><ul id='H44sQ'></ul>
                  <legend id='H44sQ'><style id='H44sQ'><dir id='H44sQ'><q id='H44sQ'></q></dir></style></legend>
                    <tbody id='H44sQ'></tbody>

                  <small id='H44sQ'></small><noframes id='H44sQ'>

                  本文介绍了无法使用 SMTP 发送电子邮件(获取 javax.mail.MessagingException:无法将套接字转换为 TLS;)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经编写了以下代码,用于使用 javamail API 通过 SMTP 作为 TLS 发送电子邮件,因为 SSL 不受支持,但我最终遇到了以下异常.请在下面查看我的代码.我使用了调试模式,在代码下面你也可以找到异常.

                  I have written the following code for sending email using javamail API through SMTP as TLS as SSL is not supported but I ended up with the following exception. Please see my code below. I have used debugging mode and below the code you can find the exception as well.

                  import java.util.Properties;
                  import javax.mail.Message;
                  import javax.mail.MessagingException;
                  import javax.mail.PasswordAuthentication;
                  import javax.mail.Session;
                  import javax.mail.Transport;
                  import javax.mail.internet.InternetAddress;
                  import javax.mail.internet.MimeMessage;
                  
                  public class SendMailTLS {
                  
                      public static void main(String[] args) {
                  
                          final String username = "---------@mydomain.com";
                          final String password = "***********";
                  
                          Properties props = new Properties();
                          props.put("mail.smtp.auth", "true");
                          props.put("mail.smtp.starttls.enable", "true");
                          props.put("mail.smtp.host", "mail.mydomain.com");
                          props.put("mail.smtp.debug", "true");
                          props.put("mail.smtp.port", "587");
                  
                          Session session = Session.getInstance(props,
                            new javax.mail.Authenticator() {
                              protected PasswordAuthentication getPasswordAuthentication() {
                                  return new PasswordAuthentication(username, password);
                              }
                            });
                          session.setDebug(true);
                  
                          try {
                  
                              Message message = new MimeMessage(session);
                              message.setFrom(new 
                                    InternetAddress("---------@mydomain.com"));
                              message.setRecipients(Message.RecipientType.TO,
                              InternetAddress.parse("---------@mydomain.com"));
                              message.setSubject("Testing Subject");
                              message.setText("Dear Mail Crawler,"
                                  + "
                  
                   No spam to my email, please!");
                  
                              Transport.send(message);
                  
                              System.out.println("Done");
                  
                          } catch (MessagingException e) {
                              throw new RuntimeException(e);
                          }
                      }
                  }
                  

                  异常跟踪

                  DEBUG: setDebug: JavaMail version 1.4.5
                  DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
                  DEBUG SMTP: useEhlo true, useAuth true
                  DEBUG SMTP: useEhlo true, useAuth true
                  DEBUG SMTP: trying to connect to host "mail.mydomain.com", port 587, isSSL false
                  220-cpanel35.per.syra.net.au ESMTP Exim 4.80 #2 Fri, 05 Oct 2012 17:28:56 +0800 
                  220-We do not authorize the use of this system to transport unsolicited, 
                  220 and/or bulk e-mail.
                  DEBUG SMTP: connected to host "mail.mydomain.com", port: 587
                  
                  EHLO xxxxxx.xxxxx.com
                  250-cpanel35.per.syra.net.au Hello xxxx.xxxxx.com [xx.xx.xx.xxx]i
                  250-SIZE 52428800
                  250-8BITMIME
                  250-PIPELINING
                  250-AUTH PLAIN LOGIN
                  250-STARTTLS
                  250 HELP
                  DEBUG SMTP: Found extension "SIZE", arg "52428800"
                  DEBUG SMTP: Found extension "8BITMIME", arg ""
                  DEBUG SMTP: Found extension "PIPELINING", arg ""
                  DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
                  DEBUG SMTP: Found extension "STARTTLS", arg ""
                  DEBUG SMTP: Found extension "HELP", arg ""
                  STARTTLS
                  220 TLS go ahead
                  Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not convert socket to TLS;
                    nested exception is:
                      javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
                      at SendMailTLS.main(SendMailTLS.java:52)
                  Caused by: javax.mail.MessagingException: Could not convert socket to TLS;
                    nested exception is:
                      javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
                      at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1918)
                      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:652)
                      at javax.mail.Service.connect(Service.java:317)
                      at javax.mail.Service.connect(Service.java:176)
                      at javax.mail.Service.connect(Service.java:125)
                      at javax.mail.Transport.send0(Transport.java:194)
                      at javax.mail.Transport.send(Transport.java:124)
                      at SendMailTLS.main(SendMailTLS.java:47)
                  Caused by: javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
                      at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
                      at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1868)
                      at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1826)
                      at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1809)
                      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1328)
                      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1305)
                      at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:548)
                      at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:485)
                      at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1913)
                      ... 7 more
                  Caused by: java.lang.RuntimeException: Could not generate DH keypair
                      at sun.security.ssl.DHCrypt.<init>(DHCrypt.java:123)
                      at sun.security.ssl.ClientHandshaker.serverKeyExchange(ClientHandshaker.java:618)
                      at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:202)
                      at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
                      at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
                      at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:998)
                      at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1294)
                      at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1321)
                      ... 11 more
                  Caused by: java.security.InvalidAlgorithmParameterException: Prime size must be multiple of 64, and can only range from 512 to 1024 (inclusive)
                      at com.sun.crypto.provider.DHKeyPairGenerator.initialize(DHKeyPairGenerator.java:120)
                      at java.security.KeyPairGenerator$Delegate.initialize(KeyPairGenerator.java:658)
                      at sun.security.ssl.DHCrypt.<init>(DHCrypt.java:117)
                      ... 18 more
                  

                  谁能帮我调试一下?提前致谢!

                  Can anyone help me debug this? Thanks in advance!

                  推荐答案

                  我通过注释掉下面的属性解决了这个问题

                  I resolved this issue by just commenting out the below property

                  props.put("mail.smtp.starttls.enable", "true"); 
                  

                  并且代码在没有错误或警告的情况下执行,或者只是从上面的源代码中删除这一行.到目前为止,它的作用就像一个魅力.

                  and the code got executed with no errors or warning or simply delete this line from the above source code. It is working like a charm till date.

                  这篇关于无法使用 SMTP 发送电子邮件(获取 javax.mail.MessagingException:无法将套接字转换为 TLS;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Java Mail 之谜 - SMTP 被阻止? 下一篇:如何强制 JavaMailSenderImpl 使用 TLS1.2?

                  相关文章

                    <bdo id='mecve'></bdo><ul id='mecve'></ul>

                      <small id='mecve'></small><noframes id='mecve'>

                      <tfoot id='mecve'></tfoot>
                      <i id='mecve'><tr id='mecve'><dt id='mecve'><q id='mecve'><span id='mecve'><b id='mecve'><form id='mecve'><ins id='mecve'></ins><ul id='mecve'></ul><sub id='mecve'></sub></form><legend id='mecve'></legend><bdo id='mecve'><pre id='mecve'><center id='mecve'></center></pre></bdo></b><th id='mecve'></th></span></q></dt></tr></i><div id='mecve'><tfoot id='mecve'></tfoot><dl id='mecve'><fieldset id='mecve'></fieldset></dl></div>

                    1. <legend id='mecve'><style id='mecve'><dir id='mecve'><q id='mecve'></q></dir></style></legend>