Reputation: 4742
My mail sending code is as follows which has been hosted on the server:
try
{
MailMessage msgMail = new MailMessage();
MailMessage myMessage = new MailMessage();
myMessage.From = new MailAddress("*****");
myMessage.To.Add(TextBox1.Text);
myMessage.Subject = "Subject";
myMessage.IsBodyHtml = true;
myMessage.Body = "Message Body";
SmtpClient mySmtpClient = new SmtpClient();
System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("email", "password");
mySmtpClient.Host = "****"; //Have specified the smtp host name
mySmtpClient.UseDefaultCredentials = false;
mySmtpClient.Credentials = myCredential;
mySmtpClient.Send(myMessage);
myMessage.Dispose();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
I keep on getting this error
System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: #5.1.0 Address rejected [email protected] at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at Mail.Button1_Click(Object sender, EventArgs e) in d:\hosting\9110120\html\FB\Mail.aspx.cs:line 37
I have tried everything.It keeps giving the same error
My site is hosted on Godaddy server
Upvotes: 1
Views: 14371
Reputation: 153
I had same problem , fixed it by a small change in the line below
System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("email", "password");
verify your credentials , that worked for me :) ..
Upvotes: 0
Reputation: 46047
It's failing because the email address doesn't exist. Just handle the exception and you should be all set.
How to check if an email address exists without sending an email?
Upvotes: 0
Reputation: 70728
Your code seems fine, apparently it could be that you need to configure it: http://support.godaddy.com/help/article/5444
Upvotes: 2