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

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

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

      <tfoot id='OG1bG'></tfoot>

      如何有效地使用 javax.mail API 发送批量邮件?&amp;我们可以使用重用经过身份验证的会话来提高速

      时间:2023-10-14
          <tbody id='2Mu5q'></tbody>
        <tfoot id='2Mu5q'></tfoot>

          <small id='2Mu5q'></small><noframes id='2Mu5q'>

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

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

              • <bdo id='2Mu5q'></bdo><ul id='2Mu5q'></ul>
                本文介绍了如何有效地使用 javax.mail API 发送批量邮件?&amp;我们可以使用重用经过身份验证的会话来提高速度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我可以使用 javax.mail API 发送邮件.但这里的问题是平均每封邮件需要大约 4.3 秒才能发送到目的地.

                I am able to send a mail using javax.mail API. But the problem here is on an average for each mail it taking around 4.3 seconds to send to destination.

                如果我按顺序发送 20 封邮件,大约需要 86.599 秒.对于我的要求,这种方法不起作用.我正在寻找一种可以在更短的时间内发送大量邮件的方法.

                If I am sending a 20 mails sequentially, it takes around 86.599 seconds. For my requirement this approach will not work. I am looking for an approach which can send large number of mails in less time.

                当我查看调试日志时,API 正在尝试对其发送的每条消息向 SMTP 服务器进行身份验证.但我只创建一次会话,并对我发送的所有邮件使用相同的会话.现在我的问题是,每次向 smtp 服务器进行身份验证时,这不是一个开销过程吗?没有更好的方法吗?

                When I looked at the debug log, the API is trying to authenticate to SMTP server for each and every message it sending. But I am creating a session only one time and using the same session for all the mails I am sending. Now my question is Isn't it a overhead process every time authenticating itself to the smtp server. Isn't there a better approach ?

                以下是您可能会发现有用的日志跟踪.

                Below is the log trace you may find helpful.

                250-AUTH LOGIN PLAIN XOAUTH XOAUTH2
                250 ENHANCEDSTATUSCODES
                DEBUG SMTP: Found extension "SIZE", arg "35882577"
                DEBUG SMTP: Found extension "8BITMIME", arg ""
                DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH XOAUTH2"
                DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
                DEBUG SMTP: Attempt to authenticate
                DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
                DEBUG SMTP: AUTH LOGIN command trace suppressed
                DEBUG SMTP: AUTH LOGIN succeeded
                

                请让我知道您对此的想法,非常感谢您提供任何帮助.

                Please let me know your thoughts on this and any help on this is really appreciated.

                -纳伦德拉

                推荐答案

                你是如何发送消息的?JavaMail FAQ 建议静态 Transport.send 方法将为每条消息打开一个新连接,因为它是一种方便的方法,可以创建合适的 Transport 实例,连接它,调用 sendMessage 和然后再次关闭连接.如果您从 Session 获得自己的 Transport 实例,您可以连接一次,然后重复调用 sendMessage 以在一个连接上发送多条消息,然后最后 close 它.类似于(未经测试):

                How are you sending the messages? The JavaMail FAQ suggests that the static Transport.send method will open a fresh connection for each message, as it is a convenience method that creates a suitable Transport instance, connects it, calls sendMessage and then closes the connection again. If you get your own Transport instance from the Session you can connect once, then call sendMessage repeatedly to send several messages on the one connection, and finally close it. Something along the lines of (untested):

                Transport t = session.getTransport();
                t.connect();
                try {
                  for(Message m : messages) {
                    m.saveChanges();
                    t.sendMessage(m, m.getAllRecipients());
                  }
                } finally {
                  t.close();
                }
                

                更新为使用资源块的尝试:

                Updated to use try with resources block:

                try (Transport t = session.getTransport()) {
                    t.connect();
                    for(Message m : messages) {
                        m.saveChanges();
                        t.sendMessage(m, m.getAllRecipients());
                    }
                }
                

                这篇关于如何有效地使用 javax.mail API 发送批量邮件?&amp;我们可以使用重用经过身份验证的会话来提高速度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:JavaMail smtp 属性(用于 STARTTLS) 下一篇:Java Mail 之谜 - SMTP 被阻止?

                相关文章

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

                  1. <small id='gtFvy'></small><noframes id='gtFvy'>

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