0

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
    ...
}
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Damiano Fusco
  • 215
  • 3
  • 6
  • Are you getting a specific exception? If you are, please post the exception message. Otherwise, it's worth raising a support ticket with GoDaddy. – dash Jun 04 '12 at 15:08
  • Have tried modifying the `System.Web.Mail` [answer](http://stackoverflow.com/a/1014876/26226) to use `System.Net.Mail`? – jrummell Jun 04 '12 at 15:08
  • 2
    Also: http://support.godaddy.com/groups/web-hosting/forum/topic/unable-to-send-mail-via-godaddys-smtp-ssl-server-via-smtpclient/ – dash Jun 04 '12 at 15:08
  • dash, I get a "Failure to send email" exception and the inner exception is "Unable to Send email" with another inner exception saying "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond" – Damiano Fusco Jun 04 '12 at 15:23
  • jrummell, no I did not try that as that answer did not actually work for me. – Damiano Fusco Jun 04 '12 at 15:24

2 Answers2

3

.NET built-in mail class doesn't support the needed SSL method (implicit SSL) and there's nothing to do with this: the reason is explained here.

There exist third-party SMTP client components that do both explicit and implicit SSL and have other cool functions. For example, Rebex.Mail or our SecureBlackbox.

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
0

The reason that it is not working is laying on the architecture of SmtpClient. SmtpClient is designed to establish the connection using plain text not ssl.

How ever, you can use native.net to re write a sender.

Try to have a look [Aegis Implicit Mail (AIM)] (http://netimplicitssl.sourceforge.net/) , it is, open source and it's code style and architecture is exactly like System.Net.Mail

You can find the detail on 465 (Implicit "SSL") and Other Ports (Explicit "TLS") [here] (https://sourceforge.net/p/netimplicitssl/wiki/Home/)

Your could be :

try
{
    MimeMailMessage 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
    MimeMailer smtpServer = new MimeMailer(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
    ...
}
Nil Null
  • 414
  • 5
  • 14