简体   繁体   English

ASP.net SMTP连接错误

[英]ASP.net SMTP connection error

The following code nets me out error after error. 以下代码使我一次又一次地出错。

        MailMessage Enveloppe = new MailMessage();

        //emails is an array of strings
        foreach ( string email in emails )
            Enveloppe.To.Add(email);

        //Setup message parameters
        Enveloppe.Subject = "Documentation";
        Enveloppe.Body = "Infinitelycoolbodyhere"
        Enveloppe.From = new MailAddress("mrzombie@stuff", "Myname");

        //files is an array of strings
        foreach ( string filename in files ) { 
            //Add attachments
            Enveloppe.Attachments.Add(new Attachment(new System.Net.WebClient().OpenRead(filename),filename.Substring(filename.LastIndexOf('/'))));
        }

        //Create the smtp client, and let it do its job
        SmtpClient Mailman = new SmtpClient("mysmtphost");
        Mailman.EnableSsl = true;
        Mailman.Port = 465;
        Mailman.DeliveryMethod = SmtpDeliveryMethod.Network;
        Mailman.Credentials = new System.Net.NetworkCredential("usernamehere", "passwordhere");
        Mailman.Send(Enveloppe);

It so happens that it either tells me that my operation timed out, or that "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond". 碰巧的是,它要么告诉我我的操作已超时,要么“连接尝试失败,因为在一段时间后被连接方未正确响应,或者连接建立失败,因为被连接的主机未能响应”。

I'm stumped, I don't see which part of it I am doing wrong 我很困惑,看不到我做错了哪一部分

Update: I can't seem to connect to the server from Telnet, at best I connect with my laptop (under ubuntu), but I never get the "200" response. 更新:我似乎无法通过Telnet连接到服务器,充其量我只能与笔记本电脑(在ubuntu下)连接,但是我从未收到“ 200”响应。 Under the windows workstation, I get a perpetual blank telnet window. 在Windows工作站下,我得到一个永久的空白telnet窗口。

I can send/receive e-mail at the specified server with Thunderbird without any problem whatsoever. 我可以使用Thunderbird在指定的服务器上发送/接收电子邮件,没有任何问题。

Finally found the culprit - somehow the connection was left hanging between the "supposedly correct" smtp server the hosting company was giving me, and the actual smtp server. 最终找到了罪魁祸首-托管公司给我的“据说正确的” SMTP服务器与实际的SMTP服务器之间的连接以某种方式悬空了。 I just changed the address of mail.domain.com to smtp.hostingdomain.com and it fixed everything. 我只是将mail.domain.com的地址更改为smtp.hostingdomain.com,它修复了所有问题。

This is just one of those "what the hell" moments that I hate. 这只是我讨厌的那些“什么事”时刻之一。 Because of it, I had to drop the feature of application-based mail-sending, but in the end my boss and I decided that we'd instead host the files somewhere and include the links in the e-mail instead of appending attached files to the mail. 因此,我不得不放弃基于应用程序的邮件发送功能,但最终我的老板和我决定,我们将文件托管在某个位置,并将链接包含在电子邮件中,而不是附加附件邮件。

So, yeah, that doesn't really answer the question, but to those who consider the solution, but you might want to put the files you want to send on a place accessible from the outside and include linkage instead. 所以,是的,这并没有真正回答问题,而是对那些考虑解决方案的人,但是您可能希望将要发送的文件放在外部可访问的位置,并包括链接。 There. 那里。

该SMTP服务器是否已在465上启动并运行,并且是否支持SSL?

Sounds like something went wrong when trying to communicate with your SMTP server(hah, no shit!). 尝试与您的SMTP服务器通信时听起来好像出了点问题(哈哈,不要说!)。

I assume you're on windows so go to Start -> Run -> 'telnet mysmtphost 465' and see the response you get in the console. 我假设您在Windows上,因此转到“开始”->“运行”->“ telnet mysmtphost 465”,然后在控制台中看到您得到的响应。

Do you see something like this? 你看到这样的东西吗?

Connected to mysmtphost.
Escape character is '^]'.
220 mysmtphost

Try enabling tracing for System.Net.Mail (looks like you are using SNM). 尝试为System.Net.Mail启用跟踪(好像您正在使用SNM)。 To do this, you will want to add the following to your .config file. 为此,您需要将以下内容添加到您的.config文件中。

<configuration>
  <system.diagnostics>
    <trace autoflush="true" />

    <sources>

      <source name="System.Net" >
        <listeners>
          <add name="MyTraceFile"/>
        </listeners>
      </source>

      <source name="System.Net.Sockets">
        <listeners>
          <add name="MyTraceFile"/>
        </listeners>
      </source>

    </sources>


    <sharedListeners>
      <add
        name="MyTraceFile"
        type="System.Diagnostics.TextWriterTraceListener"
        initializeData="System.Net.trace.log"                />
    </sharedListeners>

    <switches>
      <add name="System.Net" value="Verbose" />
      <add name="System.Net.Sockets" value="Verbose" />
    </switches>

Hopefully this should at least tell you what is happening. 希望这至少可以告诉您正在发生的事情。

I've got some more info here, on what to expect: http://systemnetmail.com/faq/4.10.aspx 我在这里有一些更多信息,可以期待什么: http : //systemnetmail.com/faq/4.10.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM