Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 487
Arjun Avatar asked Mar 30 '13 10:03

Arjun


2 Answers

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.

like image 74
Jim Mischel Avatar answered Oct 15 '22 20:10

Jim Mischel


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.

like image 38
Tomas Kubes Avatar answered Oct 15 '22 20:10

Tomas Kubes