---
title: "Set Up IIS SMTP Relay for Office 365 Email Delivery"
description: "Configure an IIS SMTP relay server for recipient email delivery from Office 365 using GUI and PowerShell."
canonical: "https://adamtheautomator.com/iis-smtp-relay/"
---

# Set Up IIS SMTP Relay for Office 365 Email Delivery

> Configure an IIS SMTP relay server for recipient email delivery from Office 365 using GUI and PowerShell.

Source: https://adamtheautomator.com/iis-smtp-relay/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Set Up IIS SMTP Relay for Office 365 Email Delivery](https://adamtheautomator.com/wp-content/uploads/2019/09/e-mail-marketing-2745489_1280.jpg)

# Set Up IIS SMTP Relay for Office 365 Email Delivery

[![](https://secure.gravatar.com/avatar/9a14f10ff1b1ec7d790d34f5b559e4d3de2d31b172e6ef266dfd8b479174d97b?s=192&d=mm&r=g)June Castillote](https://adamtheautomator.com/author/june/)5 September 20195 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[IIS](/tag/iis/)[Office 365](/tag/office-365/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Install the IIS SMTP Server Windows Feature](#install-the-iis-smtp-server-windows-feature)
*   [Using Server Manager](#using-server-manager)
*   [Using PowerShell](#using-powershell)
*   [Import a certificate (for TLS only)](#import-a-certificate-for-tls-only-)
*   [Validate the Certificate](#validate-the-certificate)
*   [Configure the IIS SMTP Server](#configure-the-iis-smtp-server)
*   [Add Allowed IPs in the IIS SMTP Server](#add-allowed-ips-in-the-iis-smtp-server)
*   [Confirm Certificate is Detected by the SMTP Server and Enable TLS Encryption](#confirm-certificate-is-detected-by-the-smtp-server-and-enable-tls-encryption)
*   [Test the IIS SMTP Mail Relay Server](#test-the-iis-smtp-mail-relay-server)
*   [Test with the Pickup Directory](#test-with-the-pickup-directory)
*   [Test with PowerShell](#test-with-powershell)
*   [Summary](#summary)
*   [Further Reading](#further-reading)

Microsoft IIS can serve the role of an SMTP quite nicely but requires quite a few steps to get set up. Lucky for you, I’ve set up an IIS SMTP relay server and documented all of the steps!

In this article, we will cover all of the steps needed to successfully set up an SMTP relay server to send an outgoing email with Office 365. Technically, we will use this SMTP relay to relay email to Office 365; it can just as quickly work for any general SMTP relay mail delivery purposes.

## Prerequisites

To get IIS set up and follow along with me, be sure you have a _Windows Server 2016_ machine available. I’ll also be assuming you are logged into the server as an administrator.

## Install the IIS SMTP Server Windows Feature

The first task you’ll need to do to get an IIS SMTP relay set up is to install the IIS SMTP Server. You’ll need to install the _SMTP Server_ Windows feature.

### Using Server Manager

If you’re unfamiliar with installing Windows features via Server Manager, check out this article entitled [Install or Uninstall Roles, Role Services or Features](https://docs.microsoft.com/en-us/windows-server/administration/server-manager/install-or-uninstall-roles-role-services-or-features#install-roles-role-services-and-features-by-using-the-add-roles-and-features-wizard).

### Using PowerShell

Installing the SMTP Server feature removes a lot of point and clicking. Open up a PowerShell console as administrator and run the line below:

```powershell
PS51> Install-WindowsFeature -Name SMTP-Server -IncludeAllSubFeature -IncludeManagementTools -Restart
```

Wait for the installation to finish. You should see an output similar to this.

![Installing the SMTP-Server Windows feature with PowerShell](https://adamtheautomator.com/wp-content/uploads/2020/06/ait-for-the-installation-to-finish.-You-should-see-an-output-similar-to-this..png "image_tooltip")

Installing the SMTP-Server Windows feature with PowerShell

## Import a certificate (for TLS only)

If you’ll be sending e-mail via TLS (Office 365), you need to import an SSL certificate in the server’s local machine personal certificate store before you configure the IIS SMTP Server. You can skip this step if your [Office 365 SMTP relay](https://adamtheautomator.com/office-365-smtp-relay/ "Office 365 SMTP relay") is non-TLS.

If you don’t have a certificate, you can get one via your internal PKI (if you have that) or a public certificate using services like LetsEncrypt, Digicert, etc.

Once you have the certificate, you’ll need to import it into the local machine personal certificate store. If you’re unfamiliar with how to import certificates using the Certificates MMC, check out [Import and Export Certificate – Microsoft Windows](https://support.globalsign.com/ssl/ssl-certificates-installation/import-and-export-certificate-microsoft-windows).

When successful, you should get a confirmation window like this. Click _OK_ **(1)** to confirm.

![Successful certificate import](https://adamtheautomator.com/wp-content/uploads/2020/06/When-successful-you-should-get-a-confirmation-window-like-this.-Click-OK-1-to-confirm..png "image_tooltip")

Successful certificate import

Back in the main console window, refresh the _Personal_ **_\>_** _Certificates_ folder and you should be able to see the imported certificate.

### Validate the Certificate

Once imported, be sure to verify that the certificate chain is complete and that there are no errors.  If all is well, you should be able to open the certificate and see the _Valid From_ field is current and there is a _private key_ associated with the certificate. An example is shown below.

![Validating certificate](https://adamtheautomator.com/wp-content/uploads/2020/06/Valid-From-field-is-current-and-there-is-a-private-key-associated-with-the-certificate.-An-example-is-shown-below..png "image_tooltip")

Validating certificate

On the _Certification Path_ tab, you should also see a _Certificate status_ stating that the certificate is OK as shown below.

![Certificate status stating that the certificate is OK](https://adamtheautomator.com/wp-content/uploads/2020/06/Valid-From-field-is-current-and-there-is-a-private-key-associated-with-the-certificate.-An-example-is-shown-below.2.png "image_tooltip")

_Certificate status_ stating that the certificate is OK

## Configure the IIS SMTP Server

You have successfully installed the SMTP server at this point. But before you can use it, the server settings must be configured first.

The SMTP server is running on IIS6 Compatibility mode and it does not come with built-in PowerShell support. This means that you will configure the settings manually using the IIS6 Management Console.

Go to Start –> Run and type in _inetmgr6_ and hit Enter_._ This will open the IIS 6 console.

Once the console is open, right-click on _\[SMTP Virtual Server #1\]_ **_(1)_**,  then select _Properties_ **_(2)._**

![Checking SMTP Virtual Server properties](https://adamtheautomator.com/wp-content/uploads/2020/06/SMTP-Virtual-Server-1-1-then-select-Properties-2..png "image_tooltip")

Checking SMTP Virtual Server properties

In the _Properties_ window, check _Enable logging_ **_(1)_**, then click _Properties_ **_(2)_**.

![Enabling logging](https://adamtheautomator.com/wp-content/uploads/2020/06/SMTP-Virtual-Server-1-1-then-select-Properties-2..2.png "image_tooltip")

Enabling logging

Go to the _Advanced_ tab, and _check all the boxes in the list_ **_(1)_**, then click _OK_ **_(2)._**

![Checking advanced options](https://adamtheautomator.com/wp-content/uploads/2020/06/SMTP-Virtual-Server-1-1-then-select-Properties-2..3.png "image_tooltip")

Checking advanced options

Back in the _Properties_ window, go to the _Delivery_ tab and click on _Advanced_ **_(1)._**

![Clicking Advanced button on Delivery tab](https://adamtheautomator.com/wp-content/uploads/2020/06/SMTP-Virtual-Server-1-1-then-select-Properties-2..4.png "image_tooltip")

Clicking Advanced button on Delivery tab

In the _Advanced Delivery_ window, type in the _Fully-qualified domain name_ **(1)** you’d like to use for the destination SMTP mail server. It does not have to be the same as the FQDN of the computer itself. If you’re configuring this SMTP server to use with Office 365, in the _Smart host_ **_(2)_** field, define your Office 365 MX endpoint. and click _OK_ **_(3)_**.

![Setting smart host](https://adamtheautomator.com/wp-content/uploads/2020/06/in-the-Smart-host-2-field-define-your-Office-365-MX-endpoint.-and-click-OK-3..png "image_tooltip")

Setting smart host

## Add Allowed IPs in the IIS SMTP Server

Now if you have a device that you want to test, you must add its IP address to the relay restrictions first. For this example, the IP address _192.168.0.3_ will be added to the relay restrictions. This IP address belongs to a computer that is within the same network as the server.

To add an allowed IP in the relay restrictions, go to the _Access_ tab and click on _Relay_ **_(1)_**.

![Relay button on Access tab](https://adamtheautomator.com/wp-content/uploads/2020/06/To-add-an-allowed-IP-in-the-relay-restrictions-go-to-the-Access-tab-and-click-on-Relay-1..png "image_tooltip")

Relay button on Access tab

Inside the _Relay Restrictions_ window, click _Add_ **_(1)._**

![Adding a relay restriction](https://adamtheautomator.com/wp-content/uploads/2020/06/To-add-an-allowed-IP-in-the-relay-restrictions-go-to-the-Access-tab-and-click-on-Relay-1..2.png "image_tooltip")

Adding a relay restriction

Then type in the _IP address_ **_(1)_** you’d like to allow then click _OK_ **_(2)_**.

![Restricting relay to only a single IP](https://adamtheautomator.com/wp-content/uploads/2020/06/To-add-an-allowed-IP-in-the-relay-restrictions-go-to-the-Access-tab-and-click-on-Relay-1..3.png "image_tooltip")

Restricting relay to only a single IP

Back in the _Relay Restrictions_ window, confirm that the IP address is added to the list, then click _OK_ **_(1)_** and OK out of the properties window.

![Confirming new relay restriction](https://adamtheautomator.com/wp-content/uploads/2020/06/To-add-an-allowed-IP-in-the-relay-restrictions-go-to-the-Access-tab-and-click-on-Relay-1.4.png "image_tooltip")

Confirming new relay restriction

## Confirm Certificate is Detected by the SMTP Server and Enable TLS Encryption

If your relay server will be sending outbound email via TLS, you’ll need to confirm the certificate is seen by the IIS SMTP Server and enable TLS encryption.

On the _Access_ tab of the SMTP Server properties, you should see a message stating “A TLS certificate is found with expiration date: XXXXXX”. If so, you’re good to go.

![Inspecting TLS certification expiration date](https://adamtheautomator.com/wp-content/uploads/2020/06/tating.png "image_tooltip")

Inspecting TLS certification expiration date

Next, click on the _Delivery_ tab, click on _Outbound Security_ **_(1)_**, check the _TLS encryption_ **_(2)_** box, click _OK_ **_(3)_**.

![Setting TLS encryption on outbound email](https://adamtheautomator.com/wp-content/uploads/2020/06/tating2.png)

Setting TLS encryption on outbound email

This concludes the IIS SMTP Server configuration steps.

## Test the IIS SMTP Mail Relay Server

At this point, your SMTP Server should be configured and ready to begin relaying mail. The next step is to test it. You should now test sending email through the SMTP relay to confirm the receiving SMTP server gets the message.

### Test with the Pickup Directory

When IIS SMTP Server is installed, it will create a folder on the server at _C:\\inetpub\\mailroot\\Pickup_. This directory is where the SMTP service picks up newly submitted emails for processing before moving them to the _Queue_ directory.

To test using this method, create a plain text file with content similar to this:

```powershell
From: myname@yourdomain.com
To: someone@somedomain.com,someone@NotYourDomain.com
Subject: testing Pickup directory
This is the test message body.
```

> _Do not forget to change the From and To values to your own._

Now save this file somewhere other than the pickup directory as _mail.txt_.

Once you’ve saved the file, copy and paste the file into the _C:\\inetpub\\mailroot\\Pickup_ folder_._ If successful, the file should quickly disappear. This means that the SMTP service has picked it up and has started processing the message.

After a few seconds to a minute, you should receive the email sent to the specified recipient email address defined in _mail.txt_.

#### Test with PowerShell

In this test, you will use PowerShell from the computer whose IP address you added in the _Add Allowed IPs in the IIS SMTP Server_ section.

Open up a PowerShell console and copy/paste the code below. Be sure to edit the values for the `From`, `To` and `SmtpServer` parameters. Depending on how you configured the relay server above, you can use either example below to test a non-TLS or TLS setup.

```powershell
## Build the message parameters
$mailParams = @{
    SmtpServer                 = 'smtp.server.here'
    Port                       = 25
    #UseSSL = $true   
    From                       = 'sender@yourdomain.com'
    To                         = 'recipient@yourdomain.com', 'recipient@NotYourDomain.com'
    Subject                    = ('ON-PREM SMTP Relay - ' + (Get-Date -Format g))
    Body                       = 'This is a test email using ON-PREM SMTP Relay'
    DeliveryNotificationOption = 'OnFailure', 'OnSuccess'
}
<# Send the message #>
Send-MailMessage @mailParams
```

## Summary

In this article, you’ve learned how to set up an IIS SMTP relay server for recipient email delivery from Office 365. We covered setting up both a non-TLS and TLS SMTP server using a combination of the GUI and PowerShell. We then tested our setup using PowerShell to confirm all is well.

## Further Reading

*   **_[Send-MailMessage: The PowerShell Way to Send Email](https://adamtheautomator.com/send-mailmessage/)_**
*   **_[Automating IIS SSL Certificate Installation with PowerShell](https://adamtheautomator.com/iis-certificate-request/)_**

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fiis-smtp-relay%2F&text=Set%20Up%20IIS%20SMTP%20Relay%20for%20Office%20365%20Email%20Delivery)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fiis-smtp-relay%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fiis-smtp-relay%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/08/Getting-Started-with-Windows-IIS-Internet-Information-Services.jpg)

### [Getting Started with Windows IIS (Internet Information Services)](/windows-iis/)

Learn how to get started with the venerable Windows IIS (Internet Information Services) and use Windows for web application hosting today!

![](https://adamtheautomator.com/wp-content/uploads/2022/03/How-to-Set-Up-and-Use-the-IIS-URL-Rewrite-Module.jpg)

### [Set Up and Use the IIS URL Rewrite Module (Step by Step)](/iis-url-rewrite/)

Learn how to securely redirect URLs and fix broken links to your website with the IIS URL Rewrite module on your server in this step-by-step tutorial!

![](https://adamtheautomator.com/wp-content/uploads/2021/10/How-to-Export-an-Office-365-PST-with-eDiscovery.jpg)

### [How to Export Office 365 PST with eDiscovery](/export-office-365-pst/)

If you need to archive an Office 365 mailbox, let eDiscovery lend a hand. Learn how to export Office 365 PST file via eDiscovery on this step-by-step tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
