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
I've learned the answer. The answer is:
Because System.Net.Mail does not support "implicit" SSL, only "explicit" SSL.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With