Sunday, May 23, 2010

goDaddy hosting, send emails using asp.net

I had very hard time in sending emails using asp.net on go daddy shared hosting.

I tried many options like ssl, default credentials, smtp, ports etc.

Finally below settings worked:
1) Setting From Email (abc@domainHostedOnGoDaddy.com)
2) SmtpClient as relay-hosting.secureserver.net
3) Disabling the SSL
4) Settings Credentials with username and password

Code

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

//set the addresses
mail.From = new System.Net.Mail.MailAddress("abc@domainHostedOnGoDaddy.com)","ABC");
mail.To.Add("recipientEMail");

//set the content
mail.Subject = "New Enquiry";
mail.IsBodyHtml = true;
mail.Body = "some message";

//set the smtp settings
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("relay-hosting.secureserver.net");
smtp.EnableSsl = false;

smtp.Credentials = new System.Net.NetworkCredential("abc@domainHostedOnGoDaddy.com","passwordofthisemail");

//send email
smtp.Send(mail);

lblMessage.Text = "email sent.";