[c#] Mailbox unavailable. The server response was: 5.7.1 Unable to relay Error

I have Hosted one of my website on netsol server. From there a contact.aspx has to send email using exchange server. When I attempt to send an email:

Error: Mailbox unavailable. The server response was: 5.7.1 Unable to relay

Code:

MailMessage message = new MailMessage(@"[email protected]", 
                                      @"[email protected]",
                                       "New Message",
                                       "Exchange");
SmtpClient mail = new SmtpClient("exchange.abc.com", 29);
mail.EnableSsl = true;
mail.Credentials = new NetworkCredential(@"[email protected]", @"password");
mail.UseDefaultCredentials = false;
mail.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.Send(message);

Options I tried:

  • Tested on Port 465 or 587 or 25
  • Changed SmtpDeliveryMethod.PickupDirectoryFromIis
  • can't configure IIS (SMTP server) as it is hosted on someone else's server

This question is related to c# asp.net smtpclient

The answer is


The default configuration of most SMTP servers is not to relay from an untrusted source to outside domains. For example, imagine that you contact the SMTP server for foo.com and ask it to send a message to [email protected]. Because the SMTP server doesn't really know who you are, it will refuse to relay the message. If the server did do that for you, it would be considered an open relay, which is how spammers often do their thing.

If you contact the foo.com mail server and ask it to send mail to [email protected], it might let you do it. It depends on if they trust that you're who you say you are. Often, the server will try to do a reverse DNS lookup, and refuse to send mail if the IP you're sending from doesn't match the IP address of the MX record in DNS. So if you say that you're the bar.com mail server but your IP address doesn't match the MX record for bar.com, then it will refuse to deliver the message.

You'll need to talk to the administrator of that SMTP server to get the authentication information so that it will allow relay for you. You'll need to present those credentials when you contact the SMTP server. Usually it's either a user name/password, or it can use Windows permissions. Depends on the server and how it's configured.

See Unable to send emails to external domain using SMTP for an example of how to send the credentials.


WE had this issue. everything was setup fine in terms of permissions and security.

after MUCH needling around in the haystack. the issue was some sort of heuristics. in the email body , anytime a certain email address was listed, we would get the above error message from our exchange server.

it took 2 days of crazy testing and hair pulling to find this.

so if you have checked everything out, try changing the email body to only the word 'test'. If after that, your email goes out fine, you are having some sort of spam/heuristic filter issue like we were


I use Windows Server 2012 for hosting for a long time and it just stop working after a more than years without any problem. My solution was to add public IP address of the server to list of relays and enabled Windows Integrated Authentication.

I just made two changes and I don't which help.

Go to IIS 6 Manager

Go to IIS 6 Manager

Select properties of SMTP server

Select properties of SMTP server

On tab Access, select Relays

On tab Access, select Relays

Add your public IP address

Add your public IP address

Close the dialog and on the same tab click to Authentication button.

Add Integrated Windows Authentication

Add Integrated Windows Authentication

Maybe some step is not needed, but it works.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to smtpclient

Getting "The remote certificate is invalid according to the validation procedure" when SMTP server has a valid certificate Mailbox unavailable. The server response was: 5.7.1 Unable to relay Error How to send email using simple SMTP commands via Gmail? Why do I get "'property cannot be assigned" when sending an SMTP email? How to set username and password for SmtpClient object in .NET? smtpclient " failure sending mail"