I researched this on SO and could not find a truly complete answer. Many people, including myself, are able to send an email through C# System.Net.Mail by using port 25 or 587 and NOT using SSL. For example, see here: https://stackoverflow.com/questions/1317809/sending-email-using-a-godaddy-account
Others have a solution using System.Web.Mail which is obsolete though: How can I send emails through SSL SMTP with the .NET Framework?
However, it seems nobody has a solution yet on how to send the emails using SSL with port 465. Does anybody have a solution or at least knows why SSL is not working from C#?
Here is the code I'm using:
try
{
MailMessage mail = new MailMessage("sender@yourdomain.com", receivingEmail, subject, body);
string host = "smtpout.secureserver.net";
int port = 465; // it's 465 if using SSL, otherwise 25 or 587
SmtpClient smtpServer = new SmtpClient(host, port);
smtpServer.Credentials = new NetworkCredential("sender@yourdomain.com", "yourpassword");
smtpServer.EnableSsl = true;
smtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpServer.Send(mail);
}
catch (Exception ex)
{
// do something with the exception
...
}