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:
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' -> ClickOK