Reputation: 11
Below code is working fine if I send mails which are in xyz.rw domain (like [email protected], [email protected]). 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, "[email protected]", "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);
}
Upvotes: 0
Views: 14681
Reputation: 1
in my case, the solution is set the access - connection control - connection : "all except the list below" access - relay restriction - relay : "all except the list below" security - add domain users
and remember to set the firewall setting to allow port 25 outbound
Upvotes: 0
Reputation: 18944
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' -> Click OK
Upvotes: 3