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

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.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


   sudo apt-get install postfix


Create a hash db file by

  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

Change this:

# specify SMTP relay host 
    relayhost = [servername or domain or ip]:PORT

And add this at the end :

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 ;