Andrew Maddison


SMTP on Windows Server 2008

A few weeks ago I nearly setup SMTP on my Windows 2008 box, but left it until now to finish it off. Once I’d got a bit of logging working, it seemed that no matter what settings I used in web.config, I recieved the following exception:

Email sent to: subject: Username Reminder
System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for
   at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
   at System.Net.Mail.SmtpClient.Send(MailMessage message)
   at NRFLogic.Email..ctor(String toEmail, String subject, String body) in C:\path\to\project\Email.cs:line 24

The significant problem transpired to be read permissions to the metabase. Because the SMTP on server 2008 is basically an IIS6 service running in compatability mode, you have to download the IIS 6 resource tools pack (do a custom install, and untick everything except Metabase explorer.

You then need to give your app pool account read permissions to the following keys: LM/SmtpSvc and LM/SmtpSvc/1 (I also gave it read permissions to the root of LM).

Then in code I simply set the SmtpDeliveryMethod property of my SmtpClient object to “SmtpDeliveryMethod.PickupDirectoryFromIis” and deleted the <mailSettings> node from web.config completely. This seems to have done the trick.