« SharePoint 2010 and Silverlight | Main | SharePoint 2010 Speed, and Boot to VHD »
Thursday
Dec242009

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.

Reader Comments (2)

Hi John,

Thank you for this *very* useful article. This definitely put me on the right path.
Further investigation revealed that the difference between using the name and the ip address causes exchange to use a different authentication method. The one used when the server is specified by name has a problem that I think might be linked to a buffer size being too small and causes it to fail.

One extra thing I can give (this one found by trial and error I must admit) was :
Setting
smtpClient.TargetName = null
after you have set the hostname seems to force the smtp client to use the lesser authentication method in any event and allows you to specify the host by name again.

Thanks

Stephen

January 21, 2011 | Unregistered CommenterStephen Rice

Thank you so much for sharing your thoughts. I'm sure this will come up again somewhere out there :-)

January 24, 2011 | Registered CommenterJohnLiu.NET

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>