<tfoot id='ZKHju'></tfoot>
        <bdo id='ZKHju'></bdo><ul id='ZKHju'></ul>

      1. <legend id='ZKHju'><style id='ZKHju'><dir id='ZKHju'><q id='ZKHju'></q></dir></style></legend>
      2. <i id='ZKHju'><tr id='ZKHju'><dt id='ZKHju'><q id='ZKHju'><span id='ZKHju'><b id='ZKHju'><form id='ZKHju'><ins id='ZKHju'></ins><ul id='ZKHju'></ul><sub id='ZKHju'></sub></form><legend id='ZKHju'></legend><bdo id='ZKHju'><pre id='ZKHju'><center id='ZKHju'></center></pre></bdo></b><th id='ZKHju'></th></span></q></dt></tr></i><div id='ZKHju'><tfoot id='ZKHju'></tfoot><dl id='ZKHju'><fieldset id='ZKHju'></fieldset></dl></div>
      3. <small id='ZKHju'></small><noframes id='ZKHju'>

        无法连接到 SMTP 主机:smtp.gmail.com,端口:465,响应:-1

        Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1(无法连接到 SMTP 主机:smtp.gmail.com,端口:465,响应:-1)

      4. <legend id='QgYLz'><style id='QgYLz'><dir id='QgYLz'><q id='QgYLz'></q></dir></style></legend>
          <tbody id='QgYLz'></tbody>

              <tfoot id='QgYLz'></tfoot>

                • <bdo id='QgYLz'></bdo><ul id='QgYLz'></ul>

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

                • <i id='QgYLz'><tr id='QgYLz'><dt id='QgYLz'><q id='QgYLz'><span id='QgYLz'><b id='QgYLz'><form id='QgYLz'><ins id='QgYLz'></ins><ul id='QgYLz'></ul><sub id='QgYLz'></sub></form><legend id='QgYLz'></legend><bdo id='QgYLz'><pre id='QgYLz'><center id='QgYLz'></center></pre></bdo></b><th id='QgYLz'></th></span></q></dt></tr></i><div id='QgYLz'><tfoot id='QgYLz'></tfoot><dl id='QgYLz'><fieldset id='QgYLz'></fieldset></dl></div>
                  本文介绍了无法连接到 SMTP 主机:smtp.gmail.com,端口:465,响应:-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  发送邮件时出现此错误

                  java.lang.RuntimeException: javax.mail.SendFailedException: 发送失败的;嵌套异常是:类 javax.mail.MessagingException:无法连接到 SMTP 主机:smtp.gmail.com,端口:465,响应:-1

                  java.lang.RuntimeException: javax.mail.SendFailedException: Sending failed; nested exception is: class javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1

                  我的代码是:

                  Properties props = new Properties();
                  props.put("mail.smtp.host", "smtp.gmail.com");
                  props.put("mail.smtp.starttls.enable","true");
                  props.put("mail.smtp.socketFactory.port", "465");
                  props.put("mail.smtp.auth", "true");
                  props.put("mail.smtp.port", "465");
                  
                  Session session = Session.getDefaultInstance(props,
                          new javax.mail.Authenticator() {
                                  protected PasswordAuthentication getPasswordAuthentication() {
                                          return new PasswordAuthentication("email","password");
                                  }
                          });
                  
                  try {
                  
                          Message message = new MimeMessage(session);
                          message.setFrom(new InternetAddress("email"));
                          message.setRecipients(Message.RecipientType.TO,
                                          InternetAddress.parse(this.to));
                          message.setSubject("Testing");
                          message.setText("Hey, this is the testing email.");
                  
                  
                  
                          Transport.send(message);
                  

                  任何帮助将不胜感激.

                  提前致谢.

                  推荐答案

                  你需要告诉它你正在使用 SSL:

                  You need to tell it that you are using SSL:

                  props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
                  

                  如果你错过了什么,这里是工作代码:

                  In case you miss anything, here is working code:

                  String  d_email = "address@gmail.com",
                              d_uname = "Name",
                              d_password = "urpassword",
                              d_host = "smtp.gmail.com",
                              d_port  = "465",
                              m_to = "toAddress@gmail.com",
                              m_subject = "Indoors Readable File: " + params[0].getName(),
                              m_text = "This message is from Indoor Positioning App. Required file(s) are attached.";
                      Properties props = new Properties();
                      props.put("mail.smtp.user", d_email);
                      props.put("mail.smtp.host", d_host);
                      props.put("mail.smtp.port", d_port);
                      props.put("mail.smtp.starttls.enable","true");
                      props.put("mail.smtp.debug", "true");
                      props.put("mail.smtp.auth", "true");
                      props.put("mail.smtp.socketFactory.port", d_port);
                      props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
                      props.put("mail.smtp.socketFactory.fallback", "false");
                  
                      SMTPAuthenticator auth = new SMTPAuthenticator();
                      Session session = Session.getInstance(props, auth);
                      session.setDebug(true);
                  
                      MimeMessage msg = new MimeMessage(session);
                      try {
                          msg.setSubject(m_subject);
                          msg.setFrom(new InternetAddress(d_email));
                          msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to));
                  
                  Transport transport = session.getTransport("smtps");
                              transport.connect(d_host, Integer.valueOf(d_port), d_uname, d_password);
                              transport.sendMessage(msg, msg.getAllRecipients());
                              transport.close();
                  
                          } catch (AddressException e) {
                              e.printStackTrace();
                              return false;
                          } catch (MessagingException e) {
                              e.printStackTrace();
                              return false;
                          }
                  

                  这篇关于无法连接到 SMTP 主机:smtp.gmail.com,端口:465,响应:-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Compiling C++ for the JVM(为 JVM 编译 C++)
                  Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                  How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                  Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                  How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                  Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)

                  <tfoot id='hwFJy'></tfoot>

                  <legend id='hwFJy'><style id='hwFJy'><dir id='hwFJy'><q id='hwFJy'></q></dir></style></legend>

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

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