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

I'm getting the above error message. My code is posted below.  The code below has worked fine for several months.

This last week, I started getting the error message stated in the title of the question.  
The mailserver and the website are hosted on 2 different servers.  

Anyone know why this has stopped working?  How I can fix it?

Thanks
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
Dim mail As New MailMessage
Dim fromAddress As New MailAddress("[email protected]")
mail.From = fromAddress 
mail.To.Add("[email protected]")
mail.Subject = "blah"
mail.Body = "123, abc"

Dim mailClient As String = "myMailServer.com"
Dim smtp As New SmtpClient(mailClient)

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


If you're trying to relay via the Exchange Server (in other words, have it deliver mail to a domain it does not control), it's possible someone has reset the relay configuration and switched this behaviour off. An Exchange Server will accept mail in its default configuration for any email domains it is authoritative for, but for security reasons, it won't relay mail for other domains (this would turn it into a server abused by spammers).

What version of Exchange is the Exchange Server running, and how do you want to allow relay?

Probably the easiest method is to allow your web server's IP address to relay via the server. If Exchange 2003, do that by editing the SMTP Virtual Server and changing the Relay settings. More information at http://www.quantumsoftware.com.au/support/kb/Article.aspx?ID=50.

In Exchange 2007, this is a little more difficult. You'll need another Receive Connector, configured to accept mail from the web server's IP address, and with permissions granted to allow relay. See http://exchangepedia.com/blog/2007/01/exchange-server-2007-how-to-allow.html. Be sure to read all the security notes and ensure you understand what you are opening up before proceeding. Those notes should also apply to Exchange 2010.

-Matt
Random Solutions  
 
programming4us programming4us