How to route mail (Dovecot, Postfix setup ) to Office 365 - same domain

Posted May 29, 2015 16.3k views

Hi to all,

This is my very first post and I think is a good chance to express my gratitude and satisfaction with DO services and great community support.

I have setup a working Linux mail server on my DO droplet, however
recently, I have decided to switch over to Office 365 subscription and updated my DNS tables records to forward MX for my domain to Microsoft Exchange servers.

Everything was successful and now it was deployed in production.

On my Droplet webpage there is a contact mail form for visitors, which sends email to mailbox accounts registered on my droplet mail server.

Same mail accounts boxes are already setup in Office 365, however the problem is that all messages sent form the webpage mail form are routed locally - only on the droplet mail server itself since the domain name and mail accounts are both identical on my Linux box and Office 365 .

My setup:

On the Postfix server and Office 365 I have:

alias -
forwarded to

Is there a workaround to actually force Postfix to send the messages to external Exchange server given the fact that both servers are sending mail for

Your valuable advise and support would be highly appreciated.


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


“`sudo apt-get install libsasl2-modules
sudo apt-get install postfix

```sudo nano /etc/postfix/sasl_passwd


”`[servername or domain or ip] username:password

Create a hash db file by 

```sudo postmap /etc/postfix/sasl_passwd
  sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
  sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

“`sudo nano /etc/postfix/

Change this:

specify SMTP relay host

relayhost = [servername or domain or ip]:PORT
And add this at the end :

```# enable SASL authentication 
smtp_sasl_auth_enable = yes
# disallow methods that allow anonymous authentication. 
smtp_sasl_security_options = noanonymous
# where to find sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# Enable STARTTLS encryption 
smtp_use_tls = yes
# where to find CA certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Restart Postfixsudo service postfix restart

Test it ;

”`echo “body of your email” | mail -s “This is a Subject” -a “From: