views:

1504

answers:

4

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.

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.

 <add key="SmtpServer" value="smtp.att.yahoo.com"/>
 <add key="SmtpServerAuthenticateUser" value="[email protected]"/>
 <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:

        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

A: 

if it works with one and not the other, it's possible your settings aren't correct? you're using yahoo, but your user account is @sbcglobal.net...

Jason
sbc partnered with yahoo, and then att absorbed sbc.
Corey Trager
These setting *DO* work with System.Web.Mail.
Corey Trager
+5  A: 

I've learned the answer. The answer is:

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

Corey Trager
A: 

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!

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. :-(

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).

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.

Wayne H
A: 

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).

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.

Hope this helps!

Bryan Allred