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

3

18

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
Larimor answered 30/3, 2013 at 10:58 Comment(1)
Can you testing using @JimMischel answer ?Emogeneemollient
M
47

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.

Mazonson answered 30/3, 2013 at 13:25 Comment(2)
this affected us. When we were on a wired connection it worked. however on a wifi connection at work it didnt because of a different ip range. we had to update Exchange to also include this up rangeVerboten
Thanks for the explanation, this is the reason why i can send a mail on an address on the same host and not on other hosts.Marciamarciano
D
11

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.

Dysentery answered 17/4, 2015 at 2:56 Comment(1)
Some of us dont have the SMTP virtual server installed.Marciamarciano
S
3

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

Squilgee answered 30/3, 2015 at 17:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.