Setup Postfix Relay Server with Microsoft Exchange Email
In a later article, we will discuss how to set up the relay server as a docker container.
- A server or access to create a new server (if you are using DigitalOcean: Droplet)
- A Microsoft Exchange account. It might work with a free Outlook 365 account, but this article will be based on Microsoft Exchange which costs about $4 per month.
- Your Exchange email DNS has already been configured (You can send and receive emails on your domain)
- Access to your applications DNS settings
- Basic Linux and network skills (It’s mostly copy-paste)
Sooner or later any web application must send out emails, however, ensuring the emails are not ending up in the recipient’s spam folder, server IP is blacklisted or other obstacles can either be expensive or time-consuming.
Some solutions offer an API to this where they handle the mail server part for a fee. A lot will have a free as well, however, you will then in both cases be sharing the outgoing IP with many other clients heavily increasing the risk of being assigned a blacklisted one.
The reality for CloudMonitor has been that the low-cost solutions couldn’t tackle our email problem and the higher-priced couldn’t be justified. Searching for other solutions we decided to set up a Postfix relay server that transports the queue to Microsoft Exchange. Some of the benefits of using Microsofts Exchange are:
- World-leading mail infrastructure
- Never blacklisted
- Cheap service
Cons could be:
- No dashboard or metrics
- No API
These cons are fine for now as tracking can still be done with Matomo .
Since we are not going to handle questions about spam or sender validity, the setup of Postfix will be straight forward.
Before you start you should know the domain of your MX record. You can look up your domain at MX Toolbox to see which hostname is set for it: https://mxtoolbox.com/SuperTool.aspx?action=mx:&run=toolpage
Configure application DNS
Open your Exchange dashboard at https://admin.microsoft.com/
Under domains click Add domain
Enter the domain name you want to add (The domain of your email sender address).
Select that you will verify your domain by TXT-record.
Copy the given details to your DNS settings
Here shown how it will look in DigitalOcean
After your DNS has been added, simply choose to continue on how you want to connect your domain
Now you will be given your DNS details under MX Records, CNAME Records, and TXT Records. Insert those in your DNS settings.
Your domain is now added to Microsoft Exchange.
On a newly created Ubuntu server install Postfix:
apt install postfix postconf -e relayhost=<MX-hostname> postconf -e smtp_use_tls=yes postconf -e mynetworks=0.0.0.0/0
You must change MX-hostname with your own, but that’s it.
Make sure only you have access to the server, by, for example, restricting all incoming connections to your web server, or at minimum port 25.
Configure Microsoft Exchange
This step requires you to have a paid Exchange plan from Microsoft. It might work with the free Outlook mailbox too, but we haven’t tested it.
First go to your Exchange control panel: https://admin.exchange.microsoft.com/
Find Connectors and click Add a connector
Choose Your organization’s email server
Name your integration, we choose the name of the application
Choose Verify by IP and enter the IP of your relay server.
Click Create. Now the Exchange setup is done.
This post was originally posted on https://cloudmonitor.dk/setup-postfix-relay-server-with-microsoft-exchange-email/