Scenario:
You have various automation and reporting solutions setup that use an On-Premise Linux Postfix SMTP Servers and relays all the automated email through your On-Premise Exchange server. You are migrating your Microsoft Exchange from On-Premise Exchange server to Office 365. You may even be considering acquiring MS Office 365 Monitoring software as well. But before that you are required to configure all your On-Premise Linux Postfix SMTP Servers to communicate with Office 365 Exchange online for email delivery.
Solution:
To simplify your implementation of migration to Office 365, the most elegant method to support your On-Premise Linux Postfix SMTP Servers is to use Office Connectors. The Office 365 SMTP relay uses a connector to authenticate the mail sent from your device or application. This allows Office 365 to relay those messages to your own mailboxes as well as external recipients. Below is the pictorial representation of the email flow when using Connector.
Implementing Office 365 Exchange Connectors:
Implementing Office 365 Exchange Connectors for your Postfix SMTP servers involves creating a new Connector and updating your SMTP servers to communicate with the Connector in-place for your mail domain.
Configuring your On-Premise Linux Postfix SMTP Server’s:
- Login to your SMTP server as root user
- Open /etc/postfix/transport file for editing
- At the end of the file, update the line containing your current mail domain name to point to your Exchange Online MX record, as shown below example:
- root@smtphost:/etc/postfix# postmap /etc/postfix/transport
root@smtphost:/etc/postfix#
- root@smtphost:/etc/postfix# grep -i outlook *.*
Binary file transport.db matches
root@smtphost:/etc/postfix#
- root@smtphost:/etc/postfix# postfix reload
root@smtphost:/etc/postfix#
- root@smtphost:/etc/postfix# tail /var/log/syslog
Apr 14 08:40:01 smtphost /USR/SBIN/CRON[11697]: (root) CMD (/etc/openvpn/start_office.sh)
Apr 14 08:43:19 smtphost postfix/master[2692]: reload configuration /etc/postfix
root@smtphost:/etc/postfix#
To find your Exchange Online MX record, use below steps:
- Logon to your Office 365 Portal as admin user: https://portal.office.com/Home
- Navigate to Office 365 Admin Center
- Click on Settings > Domains > Click on your existing Domain
- Under Required DNS Settings > Exchange Online > You’ll find the entries of your MX records as shown below:
Creating Office 365 Exchange Connector:
- Logon to your Office 365 Portal as admin user: https://portal.office.com/Home
- Navigate to Office 365 Admin Center
- Click on Admin Centers > Exchange > You’ll be taken to the Exchange Admin Center
- In Exchange Admin Center > Click on Mail Flow > Click on Connectors
- Click Plus sign to add a new Connector as shown below:
- In the New Connector Wizard select below options:
- Choose From as “Your organization’s email server” and To as “Office 365”
- Give a name to your Connector along with a brief description explaining its purpose
- Choose “By verifying that the IP address of the sending server matches one of these IP addresses that belong to your organization. These IP addresses must belong to your organization exclusively. You can’t include IP addresses that are owned by third-party services. For example, you can’t include an IP address that belongs to Office 365, hotmail.com, gmail.com, verizon.com, and so on.” > Click on Plus icon and Add IP-Addresses of all your SMTP servers that you would like them to relay email to office 365 SMTP relay
- Review all the settings and Click Save
- That’s all, you have now successfully created a Connector for your Exchange Domain through which only your predefined On-Premise Linux Postfix SMTP Servers can relay emails.
Verifying the email flow from your On-Premise Linux Postfix SMTP Servers > Office 365 Exchange Online SMTP Connector > To the Recipient:
- Login to your SMTP server as root user
- Run the Mail Queue commands to send out any outstanding emails using any of below commands:
- root@smtphost:/etc/postfix# postqueue -p
Mail queue is empty
root@smtphost:/etc/postfix# mailq
Mail queue is empty
root@smtphost:/etc/postfix#
- root@smtphost:/etc/postfix# tail /var/log/mail.log
Apr 14 08:59:02 smtphost postfix/smtpd[11788]: 6A4505E4039: client=unknown[172.20.7.110]
Apr 14 08:59:02 smtphost postfix/cleanup[11790]: 6A4505E4039: message-id=<[email protected]>
Apr 14 08:59:02 smtphost postfix/qmgr[11710]: 6A4505E4039: from=
Apr 14 08:59:02 smtphost postfix/pickup[11709]: 88E455E4091: uid=1002 from=
Apr 14 08:59:02 smtphost postfix/pipe[11791]: 6A4505E4039: to=
Apr 14 08:59:02 smtphost postfix/qmgr[11710]: 6A4505E4039: removed
Apr 14 08:59:02 smtphost postfix/cleanup[11790]: 88E455E4091: message-id=<[email protected]>
Apr 14 08:59:02 smtphost postfix/qmgr[11710]: 88E455E4091: from=
Apr 14 08:59:04 smtphost postfix/smtp[11796]: 88E455E4091: to=
Apr 14 08:59:04 smtphost postfix/qmgr[11710]: 88E455E4091: removed
root@smtphost:/etc/postfix#
References:
- https://help.ubuntu.com/lts/serverguide/postfix.html
- http://secopsmonkey.com/mail-relaying-postfix-through-office-365.html
- http://secopsmonkey.com/better-mail-relaying-postfix-through-office-365.html
- https://www.clearos.com/clearfoundation/social/community/database-transport-db-is-older-than-source-file
- https://technet.microsoft.com/en-us/library/dn554323%28v=exchg.150%29.aspx?f=255&MSPPError=-2147217396#option3