Rob
Rob

Reputation: 7216

Sending email with smtp.secureserver.net with C# and GoDaddy

this is driving me absolutely crazy. I am trying to send an email through a web service written in C# through GoDaddy's servers (smtp.secureserver.net) but for some reason it's not working. Here's my code:

public static void SendMessage(string mailFrom, string mailFromDisplayName, string[] mailTo, string[] mailCc, string subject, string body)
{
    try
    {
        using (SmtpClient client = new SmtpClient("smtpout.secureserver.net"))
        {
            client.Credentials = new NetworkCredential("[email protected]", "mypassword");
            client.EnableSsl = true;

            //client.Credentials = CredentialCache.DefaultNetworkCredentials;
            //client.DeliveryMethod = SmtpDeliveryMethod.Network;

            string to = mailTo != null ? string.Join(",", mailTo) : null;
            string cc = mailCc != null ? string.Join(",", mailCc) : null;

            MailMessage mail = new MailMessage();
            mail.From = new MailAddress(mailFrom, mailFromDisplayName);
            mail.To.Add(to);

            if (cc != null)
            {
                mail.CC.Add(cc);
            }

            mail.Subject = subject;
            mail.Body = body.Replace(Environment.NewLine, "<BR>");
            mail.IsBodyHtml = true;

            client.Send(mail);
        }
    }
    catch (Exception ex)
    {
        // exception handling
    }
}


string[] mailTo = { "[email protected]" };
SendMessage("[email protected]", "Test Email", mailTo, null, "Secure Server Test", "Testing... Sent at: " + DateTime.Now);

Upvotes: 2

Views: 11356

Answers (2)

Dominik Ras
Dominik Ras

Reputation: 511

I had a similar issue. In my case setting the value of client object's .Port public property was the problem.

Right now, I am not setting that value at all and emails arrive quickly, even with attachments.

Upvotes: 0

Rob
Rob

Reputation: 7216

GOT IT!!! Need to remove the line "client.EnableSsl = true;" because godaddy does not accept secure connections.

Upvotes: 3

Related Questions