<legend id='2qzzE'><style id='2qzzE'><dir id='2qzzE'><q id='2qzzE'></q></dir></style></legend>

  1. <small id='2qzzE'></small><noframes id='2qzzE'>

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

    1. 使用 Javamail 连接到 Gmail smtp 服务器会忽略指定端口并尝试使用 25

      Using Javamail to connect to Gmail smtp server ignores specified port and tries to use 25(使用 Javamail 连接到 Gmail smtp 服务器会忽略指定端口并尝试使用 25)

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

      • <tfoot id='eQ1rg'></tfoot>

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

            • <legend id='eQ1rg'><style id='eQ1rg'><dir id='eQ1rg'><q id='eQ1rg'></q></dir></style></legend>

              • 本文介绍了使用 Javamail 连接到 Gmail smtp 服务器会忽略指定端口并尝试使用 25的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试在 groovy 脚本中使用 javamail 通过 gmail 发送电子邮件.我在网上看了很多地方,但到目前为止一直无法正常工作.我在运行脚本时遇到的错误是:

                I'm trying to use javamail in a groovy script to send out an email via gmail. I've looked many places online and have been unable to get it working thus far. The error I'm getting when running my script is:

                DEBUG SMTP: useEhlo true, useAuth false
                DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 25, isSSL false
                Caught: javax.mail.SendFailedException: Send failure (javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25 (javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?))
                

                它似乎正在尝试使用端口 25,即使我已指定它应该使用端口 587.有谁知道可能导致此问题的原因,我使用 telnet 连接到端口 587 上的 smtp 服务器,Thunderbird 使用 587 端口和 STARTTLS 安全,并且能够使用 smtp 服务器成功发送邮件.这告诉我这不是阻塞的端口或连接问题.这是我用来尝试发送电子邮件的代码:

                It appears to be trying to use port 25 even though I've specified that it should use port 587. Does anyone know what could be causing this problem, I've used telnet to connect to the smtp server on port 587, and thunderbird uses port 587 with STARTTLS security and is able to successfully send mail using the smtp server. This tells me that it is not a blocked port or connectivity issue. Here is the code I'm using to try and send the email:

                import javax.mail.*
                import javax.mail.internet.*
                
                private class SMTPAuthenticator extends Authenticator
                {
                    public PasswordAuthentication getPasswordAuthentication()
                    {
                        return new PasswordAuthentication('email@gmail.com', 'password');
                    }
                }
                
                def  d_email = "email@gmail.com",
                        d_password = "password",
                        d_host = "smtp.gmail.com",
                        d_port  = "587", //465,587
                        m_to = "email@gmail.com",
                        m_subject = "Testing",
                        m_text = "This is a test."
                
                def 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")
                
                def auth = new SMTPAuthenticator()
                def session = Session.getInstance(props, auth)
                session.setDebug(true);
                
                def msg = new MimeMessage(session)
                msg.setText(m_text)
                msg.setSubject(m_subject)
                msg.setFrom(new InternetAddress(d_email))
                msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to))
                Transport.send(msg)
                

                任何帮助将不胜感激.提前致谢!

                Any help would be greatly appreciated. Thanks in advance!

                -布莱恩

                推荐答案

                在 Java 中你会做类似的事情:

                In Java you would do something similar to:

                Transport transport = session.getTransport("smtps");
                transport.connect (smtp_host, smtp_port, smtp_username, smtp_password);
                transport.sendMessage(msg, msg.getAllRecipients());
                transport.close();    
                

                注意smtpS"协议.此外,现代 JVM 中不再需要 socketFactory 属性,但您可能需要将 Gmail 的mail.smtps.auth"和mail.smtps.starttls.enable"设置为true".'mail.smtps.debug' 也会有帮助.

                Note 'smtpS' protocol. Also socketFactory properties is no longer necessary in modern JVMs but you might need to set 'mail.smtps.auth' and 'mail.smtps.starttls.enable' to 'true' for Gmail. 'mail.smtps.debug' could be helpful too.

                这篇关于使用 Javamail 连接到 Gmail smtp 服务器会忽略指定端口并尝试使用 25的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                • <bdo id='FSO0e'></bdo><ul id='FSO0e'></ul>

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

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

                          <tbody id='FSO0e'></tbody>
                        • <tfoot id='FSO0e'></tfoot>
                          <legend id='FSO0e'><style id='FSO0e'><dir id='FSO0e'><q id='FSO0e'></q></dir></style></legend>