Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to send mails in C# using Outgoing Mail Servers like Gmail/Yahoo using port 465

Tags:

c#

email

Using the System.Net.Mail namespace the code used is as below.

MailMessage MyMailMessage = new MailMessage("[email protected]", "[email protected]",

"write your subject Here ", "Hi,This is the test message ");

MyMailMessage.IsBodyHtml = false;

NetworkCredential mailAuthentication = new NetworkCredential("[email protected]","xxxxxxxx");

    SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 465);

    mailClient.EnableSsl = true;

    mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;

    mailClient.UseDefaultCredentials = false;

    mailClient.Credentials = mailAuthentication;

    mailClient.Send(MyMailMessage);

Using the above code timeout exception happens if 465 port is used. 25 port works fine. In the case of yahoo account both 465 and 25 gives failure sending mail.

Is there anyway 465 port can be supported for sending mails using gmail or yahoo account.

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

Is states that Windows Mail uses System.Net.Mail to send messages - wont work with Implicit SSL.

Is there any solution to fix this problem.

Thanks in advance

like image 847
HW_Dev Avatar asked Nov 04 '22 05:11

HW_Dev


1 Answers

This is not an answer to the problem but .NET built-in mail class doesn't support the needed implicit SSL method.You have to use third-party SMTP client components for this purpose which are capable of both explicit and implicit SSL.

like image 99
Cris Avatar answered Nov 12 '22 20:11

Cris