Pages

Thursday, 15 April 2010

Problems sending Email through IIS7 (SmtpFailedRecipientException)

Moved some of our applications to a new web server (Windows Server 2008 R2 + IIS7) and now the email notifications don't work. Well, that's not entirely true because they work for all mail going to any address on our company's domain, but not to anyone else. Extremely irritating because I'm a developer, not a network specialist but, in a small company you have to wear many hats.

First, just because you have the SMTP Email feature enabled in IIS7 doesn't mean you can actually send mail. You still have to have an Smtp Virtual Server set up. You do this via the "IIS 6.0 Manager" link. Thankfully, that's not the confusing bit!

I'm rambling and, anyway, all the information above is easily discoverable online.

So, every time my ASP.Net application attempted to send an email to an external address (e.g. someone@gmail.com) the system would throw a System.Net.Mail.SmtpFailedRecipientException "Mailbox unavailable. The server response was: 5.7.1. Unable to relay for someone@gmail.com".

Here's how I fixed it...

1. In IIS 6.0 Manager right click on the SMTP virtual server and choose properties.
2. In the Access tab click the Relay button.
3. "Only the list below" and "Allow all computers which successfully..." should both be selected.
4. I thought this would be enough, but it wasn't.
5. You also have to add the IP address(es) of your server to the list (e.g. 127.0.0.1).

Et voila!

Now, as I said before, I'm not a network specialist so this is almost certainly not the 'suggested' solution; but, hey, it worked for us.

No comments:

Post a Comment