Since this is the second time this year I’ve had to fix this, I thought I should write a few things down this time. If you’ve got an ASP.NET site that just sends out the occasional email, you might have some code that looks like this:
public void Send(string from, string to, string subject, string body)
{
var msgMail = new MailMessage(from, to, subject, body);
msgMail.IsBodyHtml = true;
var server = new SmtpClient("localhost");
server.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
server.UseDefaultCredentials = true;
server.Send(msgMail);
}
(Simplified, not for production, yadda yadda yadda)
And maybe it even works. Until you switch to or do your initial deploy to a new Windows 2008 server. And you get the dreaded “cannot get IIS pickup directory” error.
Now, I regularly call myself the world’s most dangerous system administrator. It’s not what I do. I’m not especially good at it, but sometimes I need to get in there and do stuff so I can get paid for my actual work. The rest of this post is a starter checklist on things to look into if you’re getting this error. If you have further questions, I probably won’t be able to help you, so I apologize in advance. If you manage to find answers for your further questions, it’d be awesome if you could share them in the comments so other people can gain more value – one of the reasons I’m writing this up on a Saturday when I’d love to be with my family is because it took me an hour to solve this, even though I’d solved the problem once before, and not too long ago. There aren’t a lot of good solution guides online, so let’s work together to build one!
Also, securing your SMTP server is a whole other post, and the balance between sending directly from your web server and using a dedicated service, deliverability, and other email issues are separate from this post. Boom. Now let’s get on with it.
1) Is SMTP installed?
Your web server might not even have the SMTP service installed, so get into the server manager and make sure that’s in the feature list. If it’s not, you’ll need to add it.

2) Is SMTP configured?
Just having SMTP installed isn’t enough. For starters, you want to make sure the service is set to start automatically when your server boots up (I once made some nice coin troubleshooting a client setup where mail used to send but wasn’t anymore – they’d rebooted and the mail service stayed down, was all.) Go into services and make sure that the service is in there, it’s already started, and has a startup type of automatic:
After that, you’ll want to play with the SMTP server settings – I don’t know a lot about these, to be honest, so I’m not going to get into them, but you need to know that SMTP is still part of IIS 6.0, so you’ll find it in the IIS 6.0 Manager. One quick tip though, because it might get missed – some receiving servers require a fully qualified domain name, and your server might have a name like “Server15″ or something, which isn’t fully qualified, so in the SMTP properties, under the Delivery tab, click the Advanced button and put a real hostname in the fully qualified domain name field.
3) Is the firewall open?
You might get hit with some aggressive firewall rules, so now’s a good time to troubleshoot your SMTP setup in general, which you can do by telnetting to localhost on port 25 and manually sending yourself a sample mail. Here’s an approximation of the flow to do that:
telnet localhost 25
HELO somehost.com
MAIL FROM: yourname@somedomain.com
RCPT TO: the_to_address@somedomain.com
DATA
Subject: the subject of the mail
Blah blah blah message body
Then hit enter, period, enter to finish the mail.
If you can’t connect, or the mail doesn’t arrive, there’s something else wrong that you’ll need to fix, because it doesn’t matter if the pickup directory’s available.
4) Does IIS have access to the metabase?
Here’s where we get to the actual problem – chances are, the process that runs your website doesn’t have access to the IIS metabase that stores the name of the pickup directory, and this is the general cause of your error.
You’re going to need to download the IIS 6.0 resource kit. There’s a script you can use called metaacl.vbs but it didn’t work for me. Download the kit from here, install it, and then run Metabase Explorer (search for it, but mine was in Program Files (x86)\IIS Resources\Metabase Explorer)
You want to add read permissions to SmtpSvc for your IIS process (I added the IIS_IUSRS group, check your settings to see what you’re running as.)

5) Does IIS have access to the pickup directory?
This is just a bonus step, because you might get a permissions error the next time you try to send mail from your website. You need to add write permissions to the actual pickup directory for your IIS user (in my case, I added a permission for IIS_IUSRS to c:\inetpub\mailroot)
That’s more or less what it took to get things running for me, but as with any server troubleshooting, it’s possible that I clicked some magic checkbox somewhere along the way that’s also key to the process, so if you have questions, post ‘em in the comments, and if you know the answer to one of those questions, because as I said, I likely don’t, then post that as well and I’ll do my best to incorporate that data into the core post.


{ 3 comments… read them below or add one }
got the same problem, done everything you ve said but the telnet as command prompt doesnt recognise telnet.
but the problem is still there. Still says cannot get IIS directory after doing all the above
Lefty, I don’t think telnet is installed by default – sorry but I’m traveling right now and typing this on my phone so I can’t look it up easily but a quick Google should tell you how to add it. It’s probably not the problem though, as I said that’ll just affect deliverability.
Nice one chap! Although I had to add IIS_IUSRS to the “SmtpSvc>1″ node as well to get it to work.