In this post we will learn how to forward all emails of particular domain to another SMTP server or gateway.
I also used this method in different scenario.
Scenario: I have my own mail server which can host multiple virtual domains and users (postfix+mysql).
Now a client has domain called example.com and for mailing he is using google mail service. Means he has hosted his domain example.com in google apps.
Now client wants to use an email id called [email protected] only for sending emails i.e notification emails from my Mail server but wants to recieve and reply emails only from google apps(google mail server).
Here it is simple method which you can use for above given scenraio or only for just forwarding all email to SMTP server or gateway.
Follow the given below steps:
Step 1: Edit the main.cf file and append the line “transport_maps = hash:/etc/postfix/transport” and save/close the main.cf file
vi /etc/postfix/main.cf transport_maps = hash:/etc/postfix/transport
Step 2: Create a new file /etc/postfix/transport and give the smtp server address.
Syntax inside file /etc/postfix/transport:
For my secenario because I have to send all incoming email of example.com to google mail server. I use the command
dig mx google.com and selected the highest priority SMTP server FQDN.
Note: Instead of aspmx.l.google.com give SMTP FQDN of your mail server
vi /etc/postfix/transport example.com smtp:aspmx.l.google.com
Step 3 Reload or restart the postfix
/etc/init.d/postfix reload OR /etc/init.d/postfix restart
Note: for forward all domains email to other SMPT server use wild card (*) in place of domain name in file /etc/postfix/transport
Important note: If you have scenario similar to mine
spam email is biggest problem in maintaing the Mail server. If you are already managing the mail server I hope you are also aware about terms like SPF,DKIM and PTR record.
In my scenario I only have to play with DKIM and rest of the thing were already in order.
I am using opendkim and I use opendkim for generateing DKIM key in Mail server.
The only change I did , I changed the name of selector with domain name.(mostly we use selector name as default)