ASP.NET "5.7.1 Unable to relay for email" when SmtpClient.UseDefaultCredentials = true
Was looking at a problem with Andy regarding using SmtpClient.UserDefaultCredentials = true, and sending emails within an authenticated WCF service.
We can send emails within the domain without any issues, but when sending emails outside of the domain the mail server rejects us with the 5.7.1 Unable to relay for email@external.com
The easier fix would probably be to UseDefaultCredentials = false, and specify a NetworkCredential(username,password). But we were stubborn and didn’t want to have to enter a email address somewhere in the web.config.
While investigating – we realized that if we specify the mail server by IP address instead of DNS name – then the email will be delivered.
Our suspicions are that the Exchange mail server has different rule sets to decide if it trusts the source to be somewhere local. If the IP address specified is a local network IP – it seems to relax the relay rules somewhat.