<bdo id='lCJbF'></bdo><ul id='lCJbF'></ul>
  • <small id='lCJbF'></small><noframes id='lCJbF'>

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

        在 .NET 中捕获 SMTP 错误

        时间:2023-10-05

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

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

            • <bdo id='HhC6V'></bdo><ul id='HhC6V'></ul>
                <tbody id='HhC6V'></tbody>

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

                2. 本文介绍了在 .NET 中捕获 SMTP 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  通常,我会发送这样的电子邮件:

                  Normally, I'd send emails like that:

                  int statusCode = 0;
                  string error = null;
                  
                  try
                  {
                      smtp.Send(mailMessage);
                      statusCode = 250;
                  }
                  catch (SmtpFailedRecipientException e)
                  {
                      Log(String.Format("[Exception] {0}
                  	Smtp: {1}{2}:{3}
                  	Status Code: {4}
                  	Faild Recipient: {5}", e.Message, smtp.Key, smtp.Value.Host, smtp.Value.Port, e.StatusCode, e.FailedRecipient));
                  
                      statusCode = (int)e.StatusCode;
                      error = e.Message;
                  }
                  catch (SmtpException e)
                  {
                      Log(String.Format("[Exception] {0}
                  	Smtp: {1} - {2}:{3}
                  	Status Code: {4}", e.Message, smtp.Key, smtp.Value.Host, smtp.Value.Port, e.StatusCode));
                  
                      statusCode = (int)e.StatusCode;
                      error = e.Message;
                  }
                  catch (Exception e)
                  {
                      Log(String.Format("[Exception] {0}.
                  	Source: {1}
                  	Stack Trace: {2}", e.Message, e.Source, e.StackTrace));
                  
                      statusCode = -1;
                      error = "General Failure";
                  }
                  

                  但是这种方法不允许我捕获一些更高级"的 SMTP 错误,例如 No Domain、No such Email 等.

                  But this method doesn't allow me to catch some of the more "advanced" SMTP errors such as No Domain, No such Email, etc.

                  如何捕获此类 SMTP 错误?这可能吗?

                  How can I capture that kind of SMTP errors? Is that even possible?

                  例如,当我尝试在 Gmail 中向 asdfkljhadf@dgdfasdf.com 之类的地址发送邮件时,Gmail 会在一段时间后向我发送一封电子邮件,该邮件是 asdfkljhadf@dgdfasdf.com 不存在.

                  For example, when I'm trying to send in Gmail to an address such as asdfkljhadf@dgdfasdf.com, Gmail sends me after a while an Email that asdfkljhadf@dgdfasdf.com doesn't exist.

                  谢谢.

                  推荐答案

                  SMTP是一个存储转发"协议,意思是服务器可以接受一个消息进行转发,但当时不知道这个消息不能交付.因此,例如,当您告诉 ISP 的 SMTP 服务器将消息传递到invalidaddress@example.com"时,服务器的响应是好的,我会转发它".稍后,ISP 的 SMTP 服务器将联系 SMTP 服务器获取example.com",并尝试传递邮件.只有这样它才知道邮件无法投递.

                  SMTP is a "store and forward" protocol, meaning that the server can accept a message for forwarding, but not know at the time that the message can't be delivered. So, for example, when you tell your ISP's SMTP server to deliver a message to "invalidaddress@example.com", the server's response is, "Okay, I'll forward it." At some later time, the ISP's SMTP server will contact the SMTP server for "example.com", and try to deliver the message. Only then does it know that the mail is undeliverable.

                  就您的客户端和 SMTP 服务器之间的通信而言,消息已成功传递——服务器同意转发它.因此,也不例外.

                  So as far as the communication between your client and the SMTP server is concerned, the message was delivered successfully--the server agreed to forward it. Therefore, no exception.

                  这篇关于在 .NET 中捕获 SMTP 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:smtp 异常发送邮件失败? 下一篇:使用 smtpClient.send 显示进度条

                  相关文章

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

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

                3. <tfoot id='VPljQ'></tfoot>
                  <legend id='VPljQ'><style id='VPljQ'><dir id='VPljQ'><q id='VPljQ'></q></dir></style></legend>

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