On all versions of Windows Server, you can setup built-in SMTP server. This SMTP server inside the organization can serve as a mail relay receiving and sending SMTP messages from and to different devices (like senders, scanners, access control devices, etc.) and applications (web applications, SQL Reporting Services, SharePoint), which need an opportunity to send mail using an SMTP service. It is not always rational to deploy a full-featured mail infrastructure, like Microsoft Exchange Server or other mail services.
In this article we’ll show how to install, configure and test the SMTP server on Windows Server 2012 R2 serving as a mail relay. This SMTP server can only send or forward e-mails, it doesn’t have any means to receive them.
How to Install SMTP Service in Windows Server 2012 R2
SMTP server is one of the system features that can be installed through Server Manager. To do it, open Server Manager Dashboard (servermanager.exe), go to Add roles and features and check SMTP Server when you select the features. To manage the SMTP service, install management consoles, being a part of Web Server (IIS) role, so you will be prompted to install some IIS components.
Leave all the suggested options of Web Server (IIS) role and run installation.
After the components are installed, you may need to restart your computer.
SMTP Server Configuration
The SMTP server is still managed using the old school management console Internet Information Services (IIS) Manager 6. You can open this console in Server Manager: Tools-> Internet Information Services (IIS) 6.0 Manager or with the command inetmgr6.exe
In IIS 6 Manager unfold the branch with your server name, right-click SMTP Virtual Server and open its properties.
In the General tab, if necessary select the IP address, the SMTP server to respond to, and check Enable logging.
Then go to the Access tab.
Here click Authentication and make sure that the Anonymous access is enabled.
Go back to the Access tab and click Connection. Here you can specify, which devices can send e-mails using our relay. To do it, check Only the list below and enter the list of IP addresses, don’t forget about yourself (127.0.0.1).
Go to the Messages tab. Here the administrative e-mail address is specified, to which the copies of NDR messages will be delivered, as well as the restrictions of the maximum e-mail size and the number of recipients.
Go to the Delivery tab.
Then click Outbound Security. Here you specify the way of authentication on the external mail server. For example, if all e-mails will be forward to Gmail mail server and then resent to the recipients, check Basic authentication and specify the login and password of your Gmail mailbox (In Google account settings should be allowed to send mail through their SMTP servers).
Then click Advanced.
Here you specify the FQDN name of your SMTP server. Click Check DNS to make sure if the DNS record is correct.
If your server sends mail to an external SMTP server, specify its name in Smart host field (e. g., smtp.gmail.com).
Save the settings of the SMTP server.
- DNS settings are critical from the point of view of mail system availability. If your SMTP server cannot resolve names, to which e-mails are sent, the delivery won’t be possible.
- If your server sends mail to other domains, it is important that the correct PTR record is created for your IP address to resolve reverse DNS lookup. The PTR record for an external IP address has to point at the FQDN name. Otherwise, most external SMTP servers won’t get mail from you, considering your server a spammer one.
SMTPSVC Automatic Start up
Now you only have to configure the automatic startup of your SMTP server. You can do it quickly using PoSh command prompt:
set-service smtpsvc -StartupType Automatic
Start the service:
Make sure that SMTPSVC is running:
Status Name DisplayName
—— —- ————
Running smtpsvc Simple Mail Transfer Protocol (SMTP)
SMTP Server Testing
The last thing you have to do is to make sure that your SMTP server is working. It is easier to do it by creating a plain-text file smtp-test-email.txt on your desktop and copying the following text to it. Don’t forget to change the sender and recipient names to yours.
Subject: Email test
This is the test email
Copy smtp-test-email.txt to C:\inetpub\mailroot\Pickup. SMTP server monitors new files appearing in this folder, and if a file is found it will read it and try to send an e-mail with the given subject and body to the recipient specified in the To: line.
Check the recipient mailbox, and you will see this e-mail.
Send-MailMessage -SMTPServer localhost -To email@example.com -From firstname.lastname@example.org -Subject "Email test" -Body " This is the test email from PowerShell"
So we have configured our own SMTP mail relay in Windows Server 2012 R2 and and tested sending messages through it.