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.";

6 comments:

Anonymous said...

I am having the same problem too...
Can anyone solve this???

Ajay Sharma said...

use the code i put in the post.

Gopal Arora said...

i have already use this code...but it is not wrking.... when i click on send btn.. email sent sucessfully msg i got..but i never got email on id...

Ajay Sharma said...

The code works in normal conditions.
If the success message is shown then it means that the code executed successfully without any exception/error.

Reasons may be any of the following:
1) Check if the e-mail is delivered in SPAM folder
2) May be the recipient's email is in server's blacklisted domain
3) Wrong/custom MX settings on domain

Kindly raise a support ticket and explain the scenario there. Hosting people will be more accurate in solving your issue

D DEEPAK said...

"Mailbox name not allowed. The server response was: sorry, relaying denied from your location [74.205.61.228] (#5.7.1)"

I am getting above exception by using above code.

kindly find a solution for my prob please..........

Ajay Sharma said...

Deepak, can you tell me what email/value you are specifying in the MailAddress and NetworkCredential options?

The error shows that either your domain/hosting don't have relay rights or you are using wrong credentials.