Using different smarthosts in your mail environment

Hello guys! I was asked how to configure multiple domains on a Microsoft Exchange server. The reception is very easy: Add the new domain name to your Exchange server and configure your POPcon to collect the mails or configure the MX DNS entry of this domain to your fixed WAN IP. But what about sending different mail domains over different smarthosts? This feature is not included in the Exchange server and can only added via third-party tools. And i thought “Isn’t it possible to do it with tiny postfix server?” (I’ve never configured a postfix server and I have only a few linux knowledge ^^). So ok, let’s start with our experiment.

I installed Debian with Gnome in my VMware Workstation environment and installed postfix. Open Terminal and change to root user:

su -
apt-get update
apt-get install postfix

after this you can edit your configuration and add your provider smarthosts. Open the main.cf file with nano:

nano /etc/postfix/main.cf

When the setup wizards starts, choose “no configuration” we want to do it by our own 😉 This is my whole configuration (bold lines were very relevant while troubleshooting ^^):

I allowed the complete internal network. You should only add your server in “mynetworks”. After this we need to create the list relayhosts and the logins. Create/open the relayhost_maps file in the postfix folder:

Maybe you will have problems with SSL ports and authentication. Check the postfix logs and correct your “relayhost_maps”, “sasl_passwd” and “tls_policy” file. Don’t forget to delete (rm filename.db) the .db-files and postmap again. You can also install this on your Raspberry Pi if you want. I think this is a very nice service to relay from different mail domains without buying a third-party-tool. In your Exchange server, change your send connector for “*” to the debian server.

You need help with your postfix server or Debian installation? Feel free to write in the comments below.