1

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 abc@yahoo.com 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

Darren
  • 68,902
  • 24
  • 138
  • 144
vini
  • 4,657
  • 24
  • 82
  • 170

3 Answers3

2

Your code seems fine, apparently it could be that you need to configure it: http://support.godaddy.com/help/article/5444

Darren
  • 68,902
  • 24
  • 138
  • 144
  • When i am sending an email to myself on the server i receive it – vini Mar 29 '12 at 17:32
  • There maybe an issue with outgoing e-mails? If the e-mail works fine to yourself on the same server that would indicate your code is fine. – Darren Mar 29 '12 at 18:15
0

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 :) ..

Shahrukh Ahmad
  • 133
  • 1
  • 1
  • 10
0

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?

Community
  • 1
  • 1
James Johnson
  • 45,496
  • 8
  • 73
  • 110
  • The email i am actually specifying is correct this is just an example – vini Mar 29 '12 at 17:41
  • its an email address either gmail or yahoo and what do you mean inside a network? – vini Mar 29 '12 at 17:49
  • I think GoDaddy has a standard host for SMTP emails. What host are you using? And are you using the same credentials for logging into GoDaddy? – James Johnson Mar 29 '12 at 17:50
  • i have tried with both smtpout.secureserver.net and relay-hosting.secureserver.net ...... No i am not using the same credentials i have created an email address and password as was specified in Godaddy – vini Mar 29 '12 at 17:55
  • Try using the email address and password you use to login to Godaddy as the credentials. I had a similar issue before, and I think it had something to do with that. – James Johnson Mar 29 '12 at 18:06
  • I have solved my problem ! My stupid mistake thanks for helping ! – vini Mar 29 '12 at 18:24