There has been some confusion about how to setup and configure an SMTP Server or mail relay on Windows Server 2008 R2. The confusion has arisen due to the SMTP server component not being managed from with IIS 7.5 but is instead managed from the IIS 6 console. In order to have SMTP working you must install IIS 6 as a feature. The following steps will explain how to setup and configure SMTP from start to finish.
Note: The steps for installing an SMTP Server or mail relay on Windows Server 2012 are very similar except for a few minor GUI changes. See this post for the exact steps.
I have noticed a few forum posts where people are wrongly following the steps in this article thinking that they are setting up a mail server to send and receive emails for their domain – this is incorrect. The steps outlined in this post are to create a virtual SMTP Server or mail relay, which sends messages only. This is typically used when web applications generate emails and use the mail relay to deliver them. That is very different from setting up a mail server. If the latter is your desired goal and it is for a commercial operation, then I suggest you search online for steps to install and configure Microsoft Exchange Server for that purpose. If you are looking a free mail server then I recommend hMailServer.
Installing the SMTP feature
1. Click Start > Run and then enter servermanager.msc in the Open dialogue box then click OK to load Server Manager:
2. Use the Add Features Wizard to select SMTP Server on the Select Features page. To initiate this, right-click on Features and click Add Feature:
3. In the Features section check SMTP Server and click Next:
4. You may see a dialogue box like the one below stating that certain role services and features are required for SMTP:
5. Click Add Required Role Services and then you will return to the previous Features section. Ensure SMTP Server is checked then click Next.
6. In the Web Server (IIS) section, click Next to proceed to the Role Services section:
7. The Role Services should be pre-populated – IIS 6 Management Compatibility should be selected, and below it, IIS 6 Metabase Compatibility and IIS 6 Management Console should also be checked. Click Next to continue:
8. In the Confirmation section click Install:
9. In the Results section click Close to complete the installation of the SMTP Server:
Configuring the SMTP Server
The next step is to configure SMTP. To do so we will need to open Internet Information Services (IIS) Manager 6.
10. Click Start > Run and then enter inetmgr6 in the dialogue box then click OK to load IIS Manager 6.
11. In IIS 6 Manager right-click on SMTP Server and select Properties:
12. In the General tab, unless you want the SMTP Server to use a specific IP address, leave the settings as they are so that the IP address is set to (All Unassigned):
13. To proceed, click on the Access tab:
14. Click on the Authentication button and ensure Anonymous access is checked and then click OK:
15. Once back in the Access tab, click on the Connection button. Select Only the list below and then click Add. Enter 127.0.0.1 as the IP addess and then click OK:
The Connection setting controls which computers can connect to the SMTP server and send mail. By granting only localhost (127.0.0.1) access, limits only the server itself the ability to connect to the SMTP server. This is a requirement for security.
16. Click OK to return to the Access tab and then click on the Relay button. Enter 127.0.0.1 as the IP addess and then click OK:
The Relay section determines which computers can relay mail through this SMTP server. By only allowing the localhost IP address (127.0.0.1) relay permissions it means that only the server itself can relay mail. Conversely, it prevents the SMTP server from being an open relay and being used to send unsolicited spam email by other computers on the internet, which could lead to the SMTP server being blacklisted.
17. Next, go to the Messages tab. Here you can enter an email address where copies of non-delivery reports are sent to. You can also configure the location of the Badmail director, however, the default setting should suffice:
18. Next, go to the Delivery tab:
19. Click on the Outbound Security button and ensure Anonymous access is selected. As the only server that can connect and relay mail through the SMTP server is localhost this security settings is fine:
20. Click OK to return to the Delivery tab and then click on Outbound Connections. Leave the defaults as they are:
21. Click OK to return to the Delivery tab and then click on Outbound Connections, then click on the Advanced button:
Here you will need to enter the fully-qualified domain name of the SMTP server. This will be the host name or A record that has been created in your DNS zone file. This is straight-forward to do but you will have to confirm how you do this with the party that manages DNS for your domain. I have entered mail.vsysad.com as this is fully-qualified. If you click on the Check DNS button you can confirm whether your chosen name resolves successfully. In my case it does as I see the following:
22. Click OK and then OK again to exit the SMTP Virtual Server Properties.
You can also perform this test by running nslookup to confirm the existence of the host name as well as confirming the IP address it resolves to – which should be the IP address of your server:
Please note that DNS is crucial to successful email delivery. If your SMTP server cannot resolve the domains it is trying to send messages to then it will fail. Ensure that the DNS servers you have configured are able to resolve DNS queries successfully. From the above screenshot you can see that the DNS server I have configured, cachens2.dfw1.rackspace.com, was able to successfully resolve my SMTP server’s hostname, mail.vsysad.com. This is one of Rackspace’s many DNS servers and I am 100% confident it works fine.
The reason I am highlighting this is because if your SMTP Server sits within a corporate network it will likely use an internal DNS server. Often these are only configured to resolve internal namespaces therefore resolving external hostnames may fail. Also, firewall rules may block your SMTP Server from querying any DNS servers so please check and ensure DNS queries are resolved successfully and if not make sure it get fixed before going onto the testing phase below.
Another very important point about DNS is that you must ensure that you have a PTR record for reverse DNS lookups configured. The PTR record allows your SMTP Server’s public IP address to be resolved back to your hostname. Some of the major email providers perform revers DNS lookups of mail servers connecting to them as a security measure to check their credibility or reputation. Your web host should have a control panel that allows you to configure reverse DNS if you have a dedicated public IP address. Not having a PTR record will not guarantee email delivery failure but it will very likely delay email delivery and at worst may result in your messages being blocked and your host being blacklisted. I highly recommend you you configure a PTR record for your server.
Follow the instructions in this post which shows you how to verify correct DNS configuration using the SMTPDIAG tool.
Testing the SMTP Server
The next step is to verify that the SMTP server is able to send email successfully. To do this follow the steps below:
23. Create a text file on your desktop called email.txt and paste the following into it, remembering to change the email address information to reflect your own details:
From: firstname.lastname@example.org To: email@example.com Subject: Email test This is the test body of the email .
24. Save the changes to email.txt and then copy the file to C:\inetpub\mailroot\Pickup. The SMTP server monitors this folder and when it detects the email.txt file, it will read the contents and send the email to the address in the To: section. This should happen almost immediately.
25. Check the email address the email was sent to and it should arrive shortly – the email was sent to my Gmail account:
An alternative way of doing this is to use a script to perform the same email test. Simply save the code below into a file called email.vbs, remembering to change the email address information to reflect your own details:
Dim sch, cdoConfig, cdoMessage sch = "http://schemas.microsoft.com/cdo/configuration/" Set cdoConfig = CreateObject("CDO.Configuration") With cdoConfig.Fields .Item(sch & "sendusing") = 1 ' cdoSendUsingPort .Item(sch & "smtpserver") = "127.0.0.1" ' .Item(sch & "smtpserverport") = 25 .update End With Set cdoMessage = CreateObject("CDO.Message") With cdoMessage Set .Configuration = cdoConfig .From = "firstname.lastname@example.org" .To = "email@example.com" .Subject = "Email test" .TextBody = "This is the test body of the email" '.AddAttachment "c:\images\myimage.jpg" .Send End With Set cdoMessage = Nothing Set cdoConfig = Nothing MsgBox "Email Sent"
Once the file has been saved to the desktop double-click on it and it should automatically send the the email. A message box pops up to confirm that the email was sent:
Apparently there’s more than one way to skin a cat, there’s also more ways to test your mail relay server:
You can also use telnet and PowerShell to test mail sending/routing via SMTP Server. Please refer to this post to see how to do this.
You can also use an email web form application which is similar to a contact us page on a website which allows you to post some feedback, which then uses an SMTP Server to deliver the messages to specific email contacts such as firstname.lastname@example.org that monitor this information. See this post to learn how to do this using an ASP.NET 4.0 C# email web form application.
That’s all there is to it! Now you have a fully functioning STMP server that can successfully send emails. Many of the companies that I have worked with use this method to send emails generated by their web applications.
If emails are not being successfully delivered you may notice that messages are building up in specific SMTP folders. Visit this post to understand the purpose of each SMTP folder and how to approach issues when messages are queuing up in those folders.
How to test outbound mail flow with a file in the Pickup folder
IIS SMTP Folder Structure and how SMTP service works
Testing SMTP Server from the command line
Testing SMTP mail relay with ASP.NET 4.0 C# email web form