2

I setup a private email with my namecheap domain but I am having trouble sending e-mails. Below is my code. Am I missing anything? I get a timeout message each time.

//Send email to end user
MailMessage mm = new MailMessage();
foreach(string to in toList)
{
    mm.To.Add(to);
}
mm.From = new System.Net.Mail.MailAddress("fromaddress");
mm.Subject = subject;
mm.Body = body;
mm.IsBodyHtml = true;
var smtp = new SmtpClient
{
    Host = "mail.privateemail.com",
    Port = 465,
    EnableSsl = true,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    Credentials = new NetworkCredential("username", "pw"),
    Timeout = 20000
};
smtp.Send(mm);
Aracthor
  • 5,277
  • 6
  • 27
  • 53
Al Belmondo
  • 654
  • 7
  • 24
  • 1
    The timeout could be multiple things. If you have an exact error message, please post that. Potential causes off the top of my head are DNS resolution timeouts or a connection timeout. – Jacob Jul 06 '15 at 19:39
  • I can't make it work neither with 465 nor 587 as commented in another answer. It stopped working this weekend. Did you find a solution? – JAG Jun 13 '16 at 10:30
  • Not yet.. I spoke with namecheap support and they were no help. All they said was after the maintenance this weekend they were requiring secure connections on port 465 but this is still not working. – Al Belmondo Jun 13 '16 at 15:12

4 Answers4

4

Port number may be wrong. I tried with 587 and it worked on gmail.

And consider to remove timeout temporarily to get an exception and find out the detailed reason of the timeout.

ozcanovunc
  • 651
  • 1
  • 8
  • 26
  • Interesting 587 worked (I have used that with sending mail with gmail in code before also). They say to use port 465 in the docs so it is very strange. – Al Belmondo Jul 06 '15 at 20:10
  • 1
    Interesting this just stopped working as of yesterday when namecheap did maintenance on their private email application – Al Belmondo Jun 12 '16 at 06:05
0

This code is what I've used with success.

            string to = "yo@yo.com";
            string from = "help@help.com";
            MailMessage message = new MailMessage(from, to);
            message.Subject = "Using the new SMTP client.";
            message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";
            SmtpClient client = new SmtpClient("mail.privateemail.com");

            client.Credentials = new System.Net.NetworkCredential("username", "pass");
            client.Port = 587;
            client.EnableSsl = true;

            try
            {
                client.Send(message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}",
                            ex.ToString());
            }
Josh O'Bryan
  • 317
  • 2
  • 8
0

Namecheap now only supports SMTP on port 465 and implicit SSL after their most recent udpate. System.Net.Mail unfortunately does not support this (see here). A work around could be to use the System.Web.Mail namespace (just a heads up it is obsolete) however it does work as seen in this SO post.

Community
  • 1
  • 1
Al Belmondo
  • 654
  • 7
  • 24
0

The solution is:

  1. Host: smtp.privateemail.com
  2. Port: 587
  3. EnableSsl: true;
  4. SecurityProtocol: (SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12);
paul-2011
  • 565
  • 7
  • 22