• <small id='zYGgZ'></small><noframes id='zYGgZ'>

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

    1. <legend id='zYGgZ'><style id='zYGgZ'><dir id='zYGgZ'><q id='zYGgZ'></q></dir></style></legend>

        <tfoot id='zYGgZ'></tfoot>
        • <bdo id='zYGgZ'></bdo><ul id='zYGgZ'></ul>
      1. 测试 SMTP 服务器正在通过 C# 运行

        Testing SMTP server is running via C#(测试 SMTP 服务器正在通过 C# 运行)

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

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

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

                  本文介绍了测试 SMTP 服务器正在通过 C# 运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在不发送消息的情况下通过 C# 测试 SMTP 是否启动并运行.

                  How can I test SMTP is up and running via C# without sending a message.

                  我当然可以试试:

                  try{
                  // send email to "nonsense@example.com"
                  }
                  catch
                  {
                  // log "smtp is down"
                  }
                  

                  必须有一个更整洁的方法来做到这一点.

                  There must be a more tidy way to do this.

                  推荐答案

                  你可以试试对您的服务器说 EHLO 并查看它是否以 250 OK 响应.当然这个测试并不能保证你以后一定能成功发送邮件,但这是一个很好的迹象.

                  You can try saying EHLO to your server and see if it responds with 250 OK. Of course this test doesn't guarantee you that you will succeed sending the mail later, but it is a good indication.

                  这是一个示例:

                  class Program
                  {
                      static void Main(string[] args)
                      {
                          using (var client = new TcpClient())
                          {
                              var server = "smtp.gmail.com";
                              var port = 465;
                              client.Connect(server, port);
                              // As GMail requires SSL we should use SslStream
                              // If your SMTP server doesn't support SSL you can
                              // work directly with the underlying stream
                              using (var stream = client.GetStream())
                              using (var sslStream = new SslStream(stream))
                              {
                                  sslStream.AuthenticateAsClient(server);
                                  using (var writer = new StreamWriter(sslStream))
                                  using (var reader = new StreamReader(sslStream))
                                  {
                                      writer.WriteLine("EHLO " + server);
                                      writer.Flush();
                                      Console.WriteLine(reader.ReadLine());
                                      // GMail responds with: 220 mx.google.com ESMTP
                                  }
                              }
                          }
                      }
                  }
                  

                  这是代码列表期待.

                  这篇关于测试 SMTP 服务器正在通过 C# 运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
                    <bdo id='ssAvw'></bdo><ul id='ssAvw'></ul>
                        • <tfoot id='ssAvw'></tfoot>
                            <i id='ssAvw'><tr id='ssAvw'><dt id='ssAvw'><q id='ssAvw'><span id='ssAvw'><b id='ssAvw'><form id='ssAvw'><ins id='ssAvw'></ins><ul id='ssAvw'></ul><sub id='ssAvw'></sub></form><legend id='ssAvw'></legend><bdo id='ssAvw'><pre id='ssAvw'><center id='ssAvw'></center></pre></bdo></b><th id='ssAvw'></th></span></q></dt></tr></i><div id='ssAvw'><tfoot id='ssAvw'></tfoot><dl id='ssAvw'><fieldset id='ssAvw'></fieldset></dl></div>

                          • <small id='ssAvw'></small><noframes id='ssAvw'>

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