MailBox UnAvailable 5.7.1. The server response was: 5.7.1 Unable to relay

asp.net-mvc-4c#-4.0sendmailsmtp

Below code is working fine if I send mails which are in xyz.rw domain (like abcd@xyz.rw, test@xyz.rw). When I tried to send mail to my gmail account, below error occurred. Its not working for other domain mail ids

MailBox Unavailable 5.7.1. The server response was: 5.7.1 Unable to
relay

Please let me know how to fix this.

SmtpClient smtp = new SmtpClient();
smtp.Port = 25;
smtp.Host = "10.8.12.242";
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential(senderID, senderPassword);
smtp.Timeout = 30000;

MailMessage message = new MailMessage(senderID, "abcd@xyz.rw", "Information Entreprise", "Hello, that message has been sent as consiquence of mail sending test.");
try
{
    smtp.Send(message);
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

Best Answer

550 5.7.1 Unable to Relay’ code error generally occurs when the user tries to send emails outside his domain.

Causes for the error:

  1. The outgoing mail server could not identify the sender.
  2. There are some issues while authenticating the sender on the server and thus restricting them to send emails.
  3. The receiver domain’s recipient policy has imposed restrictions on the sender’s domain / department. The Exchange Database is corrupt.
  4. A properly configured mail server is extremely restrictive with relaying, to prevent it from being abused by spammers to send mails.

So, That's a config issue in the mail servier. It doesn't allow you (your IP, your sender address) to send mail to the recipient.

Solution : you need to add the address to IIS Manager. Goto IIS Manager -> Default SMTP Server -> Properties -> Access -> Relay -> allow only from the list below -> add -> 'Address Here' -> Click OK

Related Topic