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

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

        System.Net.Mail 和 MailMessage 不立即发送消息

        时间:2023-10-05
          <i id='90oBd'><tr id='90oBd'><dt id='90oBd'><q id='90oBd'><span id='90oBd'><b id='90oBd'><form id='90oBd'><ins id='90oBd'></ins><ul id='90oBd'></ul><sub id='90oBd'></sub></form><legend id='90oBd'></legend><bdo id='90oBd'><pre id='90oBd'><center id='90oBd'></center></pre></bdo></b><th id='90oBd'></th></span></q></dt></tr></i><div id='90oBd'><tfoot id='90oBd'></tfoot><dl id='90oBd'><fieldset id='90oBd'></fieldset></dl></div>
            <bdo id='90oBd'></bdo><ul id='90oBd'></ul>

            • <legend id='90oBd'><style id='90oBd'><dir id='90oBd'><q id='90oBd'></q></dir></style></legend>
                <tbody id='90oBd'></tbody>

                  <small id='90oBd'></small><noframes id='90oBd'>

                • <tfoot id='90oBd'></tfoot>
                  本文介绍了System.Net.Mail 和 MailMessage 不立即发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我使用 System.Net.Mail 发送邮件时,邮件似乎不会立即发送.他们需要一两分钟才能到达我的收件箱.一旦我退出应用程序,所有消息都会在几秒钟内收到.是否有某种邮件消息缓冲区设置可以强制 SmtpClient 立即发送消息?

                  When I sent a mail using System.Net.Mail, it seems that the messages do not send immediately. They take a minute or two before reaching my inbox. Once I quit the application, all of the messages are received within seconds though. Is there some sort of mail message buffer setting that can force SmtpClient to send messages immediately?

                  public static void SendMessage(string smtpServer, string mailFrom, string mailFromDisplayName, string[] mailTo, string[] mailCc, string subject, string body)
                  {
                      try
                      {
                          string to = mailTo != null ? string.Join(",", mailTo) : null;
                          string cc = mailCc != null ? string.Join(",", mailCc) : null;
                  
                          MailMessage mail = new MailMessage();
                          SmtpClient client = new SmtpClient(smtpServer);
                  
                          mail.From = new MailAddress(mailFrom, mailFromDisplayName);
                          mail.To.Add(to);
                  
                          if (cc != null)
                          {
                              mail.CC.Add(cc);
                          }
                  
                          mail.Subject = subject;
                          mail.Body = body.Replace(Environment.NewLine, "<BR>");
                          mail.IsBodyHtml = true;
                  
                          client.Send(mail);
                      }
                      catch (Exception ex)
                      {
                          logger.Error("Failure sending email.", ex);
                      }
                  

                  谢谢,

                  标记

                  推荐答案

                  如果你在 Dotnet 4.0 上试试这个

                  Try this, if you're on Dotnet 4.0

                  using (SmtpClient client = new SmtpClient(smtpServer))  
                  {
                      MailMessage mail = new MailMessage();
                      // your code here.
                  
                      client.Send(mail);
                  }
                  

                  这将释放您的 client 实例,使其使用 QUIT 协议元素结束其 SMTP 会话.

                  This will Dispose your client instance, causing it to wrap up its SMTP session with a QUIT protocol element.

                  如果您卡在较早的 dotnet 版本上,请尝试安排为您的程序发送的每条消息重新使用相同的 SmtpClient 实例.

                  If you're stuck on an earlier dotnet version, try arranging to re-use the same SmtpClient instance for each message your program sends.

                  当然,请记住,电子邮件本质上是一个存储转发系统,从 smtp 发送到接收的延迟没有任何同步(甚至是正式可预测的).

                  Of course, keep in mind that e-mail is inherently a store-and-forward system, and there is nothing synchronous (or even formally predictable) about delays from smtp SEND to reception.

                  这篇关于System.Net.Mail 和 MailMessage 不立即发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 System.Net.Mail 加速通过 smtp 服务器发送多封电子邮件 下一篇:在 C# 中为邮件编译 HTML 正文

                  相关文章

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

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

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

                    <tfoot id='yvv33'></tfoot>