Skip to main content

Configuring SMTP relay for Office365 / Exchange Online

You've just migrated your mailboxes to the Office365. But what to do with copiers & printers which don't want to work with Office365 account, because they don't allow to use TLS?
Or how to send error or information events from your servers if you are using simple SMTP send?
Answer is - install SMTP server feature!
I will show you how to do this using 2012R2 server as a relay for SMTP.

First: you need to install SMTP on the server
1. Go to server manager, click Add roles and features and select SMTP Server feature. Standard installation is simple -after clicking 'Next' several times and 'Finish' in the wizard you will have SMTP server installed on your machine.
2. Go to the Server Manager again and click Tools: Internet Information Services (IIS) 6.0 Manager.

SECOND: configure SMTP server properties3. Click on the [SMTP Virtual Server #1] and right click for properties



4. In the General tab in IP address section, select Advanced...:



Here you can configure port/ports on which your server will listen for connections
You can change it every time you will need it.
Click OK.

5. In the General tab you can limit connections to SMTP server to prevent flood of mails - for example from application which sent too much of them because of an error.
Use then "Limit number of connections to:" and put the number of connections.
I will leave this empty.



6. In the Access tab go to Authentication... Select Anonymous access only



Click OK.

7. Still in Access tab click Connection...I prefer to use "Only the list below".
Ir you are using this option, provide all IP addresses which will be using this SMTP server as a relay. Don't forget to add localhost: 127.0.0.1


8. Still in Access tab click Relay...Select hosts that will be relayed


9. In the messages tab you can configure message size, session size, number of messages per connection and number of recipients per message. You can change badmail directory too.

10. In the delivery tab you can play with retry, reply and expiration timeout intervals.
To configure delivery to Office365, go to Outbound Security..


11. In the Outbound Security window select Basic authentication and put your user name and password to the Office365 account, select TLS encryption. Click OK.


12. In the Delivery tab select Outbound connections...

13. In the Outbound connections window select 587 as a TCP port. Click OK.
You can configure here limit of outbound connections too.


14. In the Delivery tab, go to Advanced...Enter smtp.office365.com as a Smart host. Click OK

15. Click OK to accept all settings and close [SMTP Virtual Server#1] window.

THIRD: Add domain/domains that you are managing through the Office365

16. Go to the Domains section in SMTP Virtual Server - click Domains in the left pane.
In the right pane you should see only internal domain.

17. Add your domain that you are managing in Office365. Right click on the empty field in the right pane or on the Domain in the left pane and select New - Domain... 


18. Select Remote as a domain type, click Next


19. Enter domain name, click Finish


20. In the right pane you will see now new, added domain.


21. Click on this new domain in the right pane, do the right click and select Properties.

22. In the General tab select "Allow incoming mail to be relayed to this domain"


23. Still in General tab, select Outbound Security...

24. In the Outbound Security select Basic authentication, TLS encryption and fill in user name and password for Office365 account used to deliver mails in Office365. This is the same settings that was set in the step 11.

25. Click OK to leave the configuration menu.

26. It's always good to restart service after changes applied. So go to the IIS 6 Manager, right click IIS server name and select All Tasks - Restart IIS...




27. After service restart, refresh window with F5, click somewhere in the empty field, select [SMTP virtual server] and click Start



28. You can now test SMTP server and it's relaying function, for example using telnet.