为什么System.Net.Mail在System.Web.Mail工作的地方失败

时间:2022-09-24 08:25:05

I can get both System.Net.Mail and System.Web.Mail to work with GMail, but I can't get them both to work with smtp.att.yahoo.com.

我可以同时使用System.Net.Mail和System.Web.Mail来使用GMail,但我无法让它们与smtp.att.yahoo.com一起使用。

I get the SMTP settings from my own Web.config keys. These settings work when I send using System.Web.Mail, but fail with System.Net.Mail.

我从自己的Web.config键获取SMTP设置。使用System.Web.Mail发送时,这些设置有效,但System.Net.Mail失败。

    <add key="SmtpServer" value="smtp.att.yahoo.com"/>
    <add key="SmtpServerAuthenticateUser" value="ctrager@sbcglobal.net"/>
    <add key="SmtpServerPort" value="465"/>
    <add key="SmtpUseSSL" value="1"/>
    <add key="SmtpServerAuthenticatePassword" value="MY PASSWORD"/>

Here is the code that grabs my settings, and works with GMail, fails with att.yahoo:

以下是抓取我的设置并与GMail一起使用的代码,使用att.yahoo失败:

        SmtpClient smtp;

        if (!string.IsNullOrEmpty(Util.get_setting("SmtpServer", "")))
        {
           smtp = new SmtpClient(Util.get_setting("SmtpServer", ""));
        }
        else
        {
           smtp = new SmtpClient();
        }


        if (!string.IsNullOrEmpty(Util.get_setting("SmtpServerAuthenticatePassword", "")))
           smtp.Credentials = new System.Net.NetworkCredential(
               Util.get_setting("SmtpServerAuthenticateUser", ""), 
               Util.get_setting("SmtpServerAuthenticatePassword", ""));

        if (!string.IsNullOrEmpty(Util.get_setting("SmtpServerPort", "")))
           smtp.Port = int.Parse(Util.get_setting("SmtpServerPort", ""));

        if (Util.get_setting("SmtpUseSSL", "0") == "1")
           smtp.EnableSsl = true;

        smtp.Send(message);

Is this my problem?

这是我的问题吗?

http://blogs.msdn.com/webdav_101/archive/2008/06/02/system-net-mail-with-ssl-to-authenticate-against-port-465.aspx

3 个解决方案

#1


10  

I've learned the answer. The answer is:

我已经学到了答案。答案是:

Because System.Net.Mail does not support "implicit" SSL, only "explicit" SSL.

因为System.Net.Mail不支持“隐式”SSL,只支持“显式”SSL。

#2


2  

The previous answers concerning implicit and explicit SSL connections via System.Net.Mail is absolutely correct. The way I was able to get through this obstacle, and without having to use the now obsolete System.Web.Mail, was to use the CDO (Collaborative Data Objects).

有关通过System.Net.Mail进行隐式和显式SSL连接的先前答案是绝对正确的。我能够通过这个障碍,而不必使用现在过时的System.Web.Mail,就是使用CDO(协作数据对象)。

I detailed and gave an example on another stack overflow post (GMail SMTP via C# .Net errors on all ports) if curious. Otherwise, you can go directly to the KB article at http://support.microsoft.com/kb/310212.

我详细介绍了另一个堆栈溢出帖子(GMail SMTP通过C#.Net错误在所有端口上)如果好奇的话。否则,您可以直接访问http://support.microsoft.com/kb/310212上的知识库文章。

Hope this helps!

希望这可以帮助!

#3


1  

Gimel's answer is back to front. He says use the new System.Net.Mail library, but the problem is that System.Net.Mail does not work for SSL on port 465 like System.Web.Mail did/does work!

Gimel的回答又回到了前面。他说使用新的System.Net.Mail库,但问题是System.Net.Mail不适用于端口465上的SSL,就像System.Web.Mail那样/确实有效!

I've beaten my head against this all day and for identical settings System.Web.Mail WORKS, and System.Net.Mail DOES NOT work (at least for the SMTP server I have been testing with), and here I was thinking that I should always upgrade to Microsoft's latest offering to get the best in life. :-(

我整天都在反对这一点,并且对于相同的设置System.Web.Mail WORKS和System.Net.Mail不起作用(至少对于我一直在测试的SMTP服务器),在这里我想到了我应该总是升级到微软的最新产品,以获得最好的生活。 :-(

That link to the M$ blog seems to state it all; "System.Net.Mail only supports “Explicit SSL”." and I assume the SMTP server I have been testing with wants Implicit SSL. (It's a Yahoo server btw).

与M $博客的链接似乎说明了一切; “System.Net.Mail仅支持”显式SSL“。”我假设我一直在测试的SMTP服务器需要隐式SSL。 (这是一个雅虎服务器顺便说一句)。

Since "upgrading" to the new API will no doubt break functionality for users who have servers that require implicit SSL it seems like a step backwards to "upgrade" in this case. If you can still compile only with warnings, simply disable those warnings (0618 if I recall) and keep on trucking. Oh, and you may want to consider ensuring your application always runs against the .NET framework version you built and tested with by way of config file, just so in future if M$ rips out the old API your application is safe.

由于“升级”到新API无疑会破坏具有需要隐式SSL的服务器的用户的功能,因此在这种情况下似乎向后退一步“升级”。如果您仍然可以仅使用警告进行编译,则只需禁用这些警告(如果我记得,则为0618)并继续进行卡车运输。哦,您可能需要考虑确保您的应用程序始终针对您构建的.NET框架版本以及通过配置文件进行测试,以便将来如果M $删除旧API,您的应用程序是安全的。

#1


10  

I've learned the answer. The answer is:

我已经学到了答案。答案是:

Because System.Net.Mail does not support "implicit" SSL, only "explicit" SSL.

因为System.Net.Mail不支持“隐式”SSL,只支持“显式”SSL。

#2


2  

The previous answers concerning implicit and explicit SSL connections via System.Net.Mail is absolutely correct. The way I was able to get through this obstacle, and without having to use the now obsolete System.Web.Mail, was to use the CDO (Collaborative Data Objects).

有关通过System.Net.Mail进行隐式和显式SSL连接的先前答案是绝对正确的。我能够通过这个障碍,而不必使用现在过时的System.Web.Mail,就是使用CDO(协作数据对象)。

I detailed and gave an example on another stack overflow post (GMail SMTP via C# .Net errors on all ports) if curious. Otherwise, you can go directly to the KB article at http://support.microsoft.com/kb/310212.

我详细介绍了另一个堆栈溢出帖子(GMail SMTP通过C#.Net错误在所有端口上)如果好奇的话。否则,您可以直接访问http://support.microsoft.com/kb/310212上的知识库文章。

Hope this helps!

希望这可以帮助!

#3


1  

Gimel's answer is back to front. He says use the new System.Net.Mail library, but the problem is that System.Net.Mail does not work for SSL on port 465 like System.Web.Mail did/does work!

Gimel的回答又回到了前面。他说使用新的System.Net.Mail库,但问题是System.Net.Mail不适用于端口465上的SSL,就像System.Web.Mail那样/确实有效!

I've beaten my head against this all day and for identical settings System.Web.Mail WORKS, and System.Net.Mail DOES NOT work (at least for the SMTP server I have been testing with), and here I was thinking that I should always upgrade to Microsoft's latest offering to get the best in life. :-(

我整天都在反对这一点,并且对于相同的设置System.Web.Mail WORKS和System.Net.Mail不起作用(至少对于我一直在测试的SMTP服务器),在这里我想到了我应该总是升级到微软的最新产品,以获得最好的生活。 :-(

That link to the M$ blog seems to state it all; "System.Net.Mail only supports “Explicit SSL”." and I assume the SMTP server I have been testing with wants Implicit SSL. (It's a Yahoo server btw).

与M $博客的链接似乎说明了一切; “System.Net.Mail仅支持”显式SSL“。”我假设我一直在测试的SMTP服务器需要隐式SSL。 (这是一个雅虎服务器顺便说一句)。

Since "upgrading" to the new API will no doubt break functionality for users who have servers that require implicit SSL it seems like a step backwards to "upgrade" in this case. If you can still compile only with warnings, simply disable those warnings (0618 if I recall) and keep on trucking. Oh, and you may want to consider ensuring your application always runs against the .NET framework version you built and tested with by way of config file, just so in future if M$ rips out the old API your application is safe.

由于“升级”到新API无疑会破坏具有需要隐式SSL的服务器的用户的功能,因此在这种情况下似乎向后退一步“升级”。如果您仍然可以仅使用警告进行编译,则只需禁用这些警告(如果我记得,则为0618)并继续进行卡车运输。哦,您可能需要考虑确保您的应用程序始终针对您构建的.NET框架版本以及通过配置文件进行测试,以便将来如果M $删除旧API,您的应用程序是安全的。