Pages

Showing posts with label IIS7. Show all posts
Showing posts with label IIS7. Show all posts

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.

Monday, 15 February 2010

Automatically Redirect Http Requests to Https on IIS 7

Our main website application used to have a structure that would allow the user to land on an http page and then login to a secure area. This has now changed so that the entire site has to be under SSL. The result of this is that we can no longer 'code' for this redirect. JPPinto has written a great blog entry that describes how to do it outside of your application, just using IIS.


Friday, 6 March 2009

Securing Multiple Sub Domains in IIS 7 with Wildcard SSL

This used to be a real pain in IIS 6.0 but it's gotten a lot easier in IIS 7.

Let's say you set up a web server with the following sites...
  • www.site.com
  • test.site.com
You could bind each individual site to a specific IP Address but this can be expensive and simply doesn't scale. What you should be doing is using Host Headers to help IIS differentiate requests for the different end-points. For a good overview of how to do this take a look at Setting Host Headers in IIS 6.0.

Now, you can do exactly the same thing with https - but there's no UI for it. Possibly the most requested feature hasn't made it into IIS 7. Amazing!

So, here's what to do...
  1. Add a new binding for the web site. Set it to be https, keep the default port and choose the SSL Certificate from the dropdown.
  2. Open <$System32>/inetsrv/Config/applicationHost.xml.
  3. Search for the host header for that site.
  4. Edit the https binding by appending the host header (it follows the same pattern as the http entry.