How to configure postfix relay to Office365 on Ubuntu
First we need to install postfix
server and mailutils
(simple mail commands that will help testing our configuration).
sudo apt-get update
sudo apt-get install postfix mailutils
On the configuration page chose “Internet Site” and continue with the default setting in the next step. Since the whole purpose of our mail server is to just relay all messages to Office365 it is not necessary to configure external domain.
Once installation completes we need to configure postfix; open /etc/postfix/main.cf
sudo nano /etc/postfix/main.cf
For the relayhost
add smtp.office365.com
and port 587
relayhost = [smtp.office365.com]:587
Since we will be using this mail server locally we want to protect it by saying that we only accept connections from localhost
. So modify this two setting:
Normally you want to use secure connection to Office365 so it is necessary to configure postfix
to use TLS. Add this code at the end of the config file and save the file.
Next we need to configure the sasl_passwd
and generic
files.
The sasl_passwd
holds information for the Office365 account used to relay the emails. Create the file by typing:
and add this line to the file
Change the username@yourdomain
with your account and office365password
with the account password and save the file.
Next we need to set correct file permissions and hash the file for use in postfix
.
Next we need to configure generic
file in order to be able to send emails as a valid user (this is required for Office365).
and add this two lines
substitute user@domain.com
with your Office365 account used previously. Now lets set correct file permissions and hash the file for use in postfix
.
Our configuration is done. Lets restart postfix
and test.
If you did not receive the test email then check the log files at /var/log/mail.log
Common problems
If you you are trying to send an email from user@domain.com
to other user in the same @domain.com
domain and in the main.cf
file for the mydestination
setting you have added domain.com
then the email will not be sent because postfix thinks this is a local relay. Try removing domain.com
from the mydestination
setting.
Copyright © Asia Pacific University. All Rights Reserved.