There has been some confusion about how to setup and configure SMTP 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.
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:
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 the IP address of your 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: email@example.com To: firstname.lastname@example.org 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 = "email@example.com" .To = "firstname.lastname@example.org" .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:
Note: You can also use telnet and PowerShell to test mail sending/routing via SMTP Server.
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.
It is essential to have DNS setup and working properly, if not you may experience problems with mail delivery. Follow the instructions in this post which shows you how to verify correct DNS configuration using the SMTPDIAG tool. 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 hosts use this technique to block spammers. Your web host should have a control panel that allows you to configure reverse DNS if you have a dedicated public IP address. Rackspace Cloud users can follow this link for instructions on how to create a reverse DNS record.
If emails are not being successfully delivered you may notice that messages are building up in specific SMTP folders. These are likely to be, but not limited to, Badmail & Queue. Please visit this post to understand the purpose of each SMTP folder and how to approach issues when messages are queuing up in those folders.
This page was last modified on Saturday, 12th July 2014 at 09:29:39 by Gary Keeling. © 2019 GKWeb Design.
Categorised as: Windows Servers