Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 我们如何记录与SmtpClient的SMTP对话?_.net_Smtpclient - Fatal编程技术网

.net 我们如何记录与SmtpClient的SMTP对话?

.net 我们如何记录与SmtpClient的SMTP对话?,.net,smtpclient,.net,Smtpclient,例如,为了进行故障排除,我需要查看SMTP消息来回的内容: OUT : EHLO machinename IN : 250-ReallyCoolEmailServer Hello [10.24.41.72] IN : 250-SIZE IN : 250-PIPELINING IN : (...and so on...) OUT : MAIL FROM: <some.address@example.com> IN : 250 <some.address@example.com

例如,为了进行故障排除,我需要查看SMTP消息来回的内容:

OUT : EHLO machinename IN : 250-ReallyCoolEmailServer Hello [10.24.41.72] IN : 250-SIZE IN : 250-PIPELINING IN : (...and so on...) OUT : MAIL FROM: <some.address@example.com> IN : 250 <some.address@example.com>... Sender ok 输出:EHLO machinename IN:250 ReallyCoolEmailServer Hello[10.24.41.72] 英寸:250码 IN:250-流水线 在:(…等等…) 发出:邮寄地址: 在:250。。。发送方ok ……等等

我在中找不到任何登录选项。这里我能找到的关于
SmtpClient
的唯一问题就是不要谈论看到实际的对话,或者谈论使用第三方工具,如WireShark


这似乎是一个相当大的遗漏,所以我猜我只是遗漏了一些基本的东西。:-)

就我自己而言,我实际上更喜欢像Wireshark这样“无偏见”的外部工具,以查看实际发生的情况
SmtpClient
确实有跟踪功能——它将输出发送到
System.Net
跟踪功能——但这不包括实际通过线路传输的数据。当然,您可以使用
System.Net.Sockets
跟踪,通过如下方式配置您的应用程序来获得:

<system.diagnostics>
  <sources>
    <source name="System.Net">
      <listeners>
        <add name="TraceFile"/>
      </listeners>
    </source>      
    <source name="System.Net.Sockets">
      <listeners>
        <add name="TraceFile"/>
      </listeners>
    </source>      
  </sources>
  <sharedListeners>
    <add
      name="TraceFile"
      type="System.Diagnostics.TextWriterTraceListener"
      initializeData="trace.log"
    />
  </sharedListeners>
  <switches>
    <add name="System.Net" value="Verbose"/>
    <add name="System.Net.Sockets" value="Verbose"/>
  </switches>
  <trace autoflush="true" />
</system.diagnostics>
资料来源:

最后,不,你没有遗漏任何东西--
SmtpClient
没有协议级别的跟踪,这确实是一个很大的遗漏

System.Net Verbose: 0 : [0992] SmtpClient::.ctor(host=127.0.0.1)
System.Net Information: 0 : [0992] Associating SmtpClient#47606018 with SmtpTransport#5689696
System.Net Verbose: 0 : [0992] Exiting SmtpClient::.ctor()  -> SmtpClient#47606018
System.Net Verbose: 0 : [0992] SmtpClient#47606018::Send(MailMessage#5138334)
System.Net Information: 0 : [0992] SmtpClient#47606018::Send(DeliveryMethod=Network)
System.Net Information: 0 : [0992] Associating SmtpClient#47606018 with MailMessage#5138334
System.Net Information: 0 : [0992] Associating SmtpTransport#5689696 with SmtpConnection#31950948
System.Net Information: 0 : [0992] Associating SmtpConnection#31950948 with ServicePoint#34920472
System.Net.Sockets Verbose: 0 : [0992] Socket#22453229::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [0992] Exiting Socket#22453229::Socket() 
System.Net.Sockets Verbose: 0 : [0992] Socket#22453229::Connect(1:25#16777318)
System.Net.Sockets Verbose: 0 : [0992] Exiting Socket#22453229::Connect() 
System.Net Information: 0 : [0992] Associating SmtpConnection#31950948 with SmtpPooledStream#48167163
System.Net.Sockets Verbose: 0 : [0992] Socket#22453229::Receive()
System.Net.Sockets Verbose: 0 : [0992] Data from Socket#22453229::Receive
System.Net.Sockets Verbose: 0 : [0992] 00000000 : 32 32 30 20 77 32 6B 20-4D 69 63 72 6F 73 6F 66 : 220 w2k Microsof
System.Net.Sockets Verbose: 0 : [0992] 00000010 : 74 20 45 53 4D 54 50 20-4D 41 49 4C 20 53 65 72 : t ESMTP MAIL Ser
System.Net.Sockets Verbose: 0 : [0992] 00000020 : 76 69 63 65 2C 20 56 65-72 73 69 6F 6E 3A 20 35 : vice, Version: 5
System.Net.Sockets Verbose: 0 : [0992] 00000030 : 2E 30 2E 32 31 39 35 2E-36 37 31 33 20 72 65 61 : .0.2195.6713 rea
System.Net.Sockets Verbose: 0 : [0992] 00000040 : 64 79 20 61 74 20 20 53-61 74 2C 20 33 31 20 44 : dy at  Sat, 31 D
System.Net.Sockets Verbose: 0 : [0992] 00000050 : 65 63 20 32 30 30 35 20-32 32 3A 31 33 3A 31 34 : ec 2005 22:13:14
System.Net.Sockets Verbose: 0 : [0992] 00000060 : 20 2D 30 36 30 30 20 0D-0A                      :  -0600 ..
System.Net.Sockets Verbose: 0 : [0992] Exiting Socket#22453229::Receive()   -> 105#105
System.Net.Sockets Verbose: 0 : [0992] Socket#22453229::Send()
System.Net.Sockets Verbose: 0 : [0992] Data from Socket#22453229::Send
System.Net.Sockets Verbose: 0 : [0992] 00000000 : 45 48 4C 4F 20 77 32 6B-0D 0A                   : EHLO w2k..
System.Net.Sockets Verbose: 0 : [0992] Exiting Socket#22453229::Send()  -> 10#10