Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm trying to send mail from my site :here is my code behind :
C#
MailMessage myMessage = new MailMessage();
       myMessage.Subject = "This is just for checking the EMail <N.n>";
       myMessage.Body = TextBox2.Text;
       myMessage.From = new MailAddress("me@mysite.com", "mysite.com");
       myMessage.To.Add(new MailAddress(TextBox1.Text, TextBox1.Text));

       SmtpClient mySmtpClient = new SmtpClient();
       mySmtpClient.Send(myMessage);


and here my web.config:
XML
<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network">
        <network host="smtp.mysite.com" userName="mysite.com" password="mypass" />
      </smtp>
    </mailSettings>
  </system.net>


but I have this Error:

MSIL
Server Error in '/' Application.
--------------------------------------------------------------------------------
Mailbox unavailable. The server response was: 5.7.1 <x@yahoo.com>... we do not relay <me@mysite.com>


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 <nima18n2000@yahoo.com>... we do not relay <N.N@nimanaqipour.com>
Source Error:

Line 31:
Line 32:         SmtpClient mySmtpClient = new SmtpClient();
Line 33:         mySmtpClient.Send(myMessage);
Line 34:     }
Line 35: }
Posted
Comments
Marrinavincent 18-May-13 4:04am    
smtpfailedrecipientexception mailbox unavailable

It looks like the configuration you are using for the SMTP protocols are resulting in a relaying operation (http://en.wikipedia.org/wiki/SMTP_relay[^])

The majority of legitimate smtp server will not support open relaying due to the abuse that can occur from spamming.

You will need to configure your application to use an appropriate SMTP gateway, which will therefore probably require authentication to be added into the equation.
 
Share this answer
 
Comments
#realJSOP 16-Mar-11 7:29am    
5'd to compensate for the pointless 1-vote.
DaveAuld 16-Mar-11 7:55am    
Thanks John.
What that means is that you have to use an account on that server in order to send emails. "Relay" is tha act of letting someone use your
server with a "from" address that is not found on the server.
 
Share this answer
 
Comments
Roger Wright 7-Mar-11 23:50pm    
Good clarification, John. A lot of people don't understand SMTP relaying, and why it's routinely blocked by resposible ISPs.
Must use in this way guys,I used this and worked!

C#
SmtpClient client = new SmtpClient("mail.somecompany.com", 25);

          // Configure the SmtpClient with the credentials used to connect
          // to the SMTP server.
          client.Credentials =
              new NetworkCredential("user@somecompany.com", "password");

          // Create the MailMessage to represent the e-mail being sent.
          using (MailMessage msg = new MailMessage())
          {
              // Configure the e-mail sender and subject.
              msg.From = new MailAddress("me@me.com");
              msg.Subject = "hi";

              // Configure the e-mail body.
              msg.Body = "Hi.";

              // Attach the files to the e-mail message and set their MIME type.
              msg.Attachments.Add(
                  new Attachment(@"..\..\Recipe10-07.cs","text/plain"));
              msg.Attachments.Add(
                  new Attachment(@".\Recipe10-07.exe",
                  "application/octet-stream"));
}
client.Send(msg);
 
Share this answer
 
Comments
DaveAuld 16-Mar-11 7:55am    
You've taken 8 months to get to the point you could have nailed the same day you posted your original question, obviously no rush then! :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900