on
tutorial
- Get link
- Other Apps
mail for superman@site.com ==> [ site.com Postfix server ] ==> forwarded to superman@gmail.com
$ sudo apt-get install postfix
$ sudo service postfix status * postfix is running
$ sudo netstat -ltnp | grep 25 tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1926/master tcp6 0 0 ::1:25 :::* LISTEN 1926/master
$ dig binarytides.com mx ; <<>> DiG 9.9.3-rpz2+rl.13214.22-P2-Ubuntu-1:9.9.3.dfsg.P2-4ubuntu1.1 <<>> binarytides.com mx ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- 08:59:17="" 0="" 10="" 127.0.1.1="" 1="" 2014="" 28="" 4096="" 65="" 7230="" 74="" 85100="" additional:="" answer:="" answer="" authority:="" binarytides.com.="" edns:="" flags:="" fri="" id:="" in="" ist="" mail.binarytides.com.="" mar="" msec="" msg="" mx="" noerror="" opcode:="" opt="" pre="" pseudosection:="" qr="" query:="" query="" question="" ra="" rcvd:="" rd="" section:="" server:="" size="" status:="" time:="" udp:="" version:="" when:="">In the 'ANSWER SECTION' it can be seen that mail.binarytides.com is reported as the mail server for binarytides.com. Next, dig up the a records for the domain mail.binarytides.com and it would show the server ip to which it points.$ dig mail.binarytides.com a ; <<>> DiG 9.9.3-rpz2+rl.13214.22-P2-Ubuntu-1:9.9.3.dfsg.P2-4ubuntu1.1 <<>> mail.binarytides.com a ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- 09:00:19="" 0="" 127.0.1.1="" 173.255.230.5="" 1="" 2014="" 28="" 30="" 4096="" 43356="" 65="" 85045="" a="" additional:="" answer:="" answer="" authority:="" edns:="" flags:="" fri="" id:="" in="" ist="" mail.binarytides.com.="" mar="" msec="" msg="" noerror="" opcode:="" opt="" pre="" pseudosection:="" qr="" query:="" query="" question="" ra="" rcvd:="" rd="" section:="" server:="" size="" status:="" time:="" udp:="" version:="" when:="">->Now the ANSWER SECTION shows the ip address of mail.binarytides.com which over here is correct. Do the same for your domain and verify that the mx records are setup correctly.Configure postfix to forward mails
Now comes the final task of configuring postfix to forward mails, and it is surprisingly simple. Find the path of the configuration directory using the postconf command$ postconf | grep config_directory config_directory = /etc/postfixNow we know that all the necessary configuration files lie in the above directory, so get inside it. Edit the main.cf file/etc/postfix/main.cfAnd add the following lines at the end of itvirtual_alias_domains = mydomain.com myanotherdomain.com virtual_alias_maps = hash:/etc/postfix/virtualThe first line virtual_alias_domains lists the domains, for which postfix is going to accept emails. Multiple domains are added separated by a space.The second line virtual_alias_maps specifies the path to the file which is going to contain mappings specifying how to forward emails for the above domains.Now open the /etc/postfix/virtual file (create one if it does not exist) and add to it the emails you want to forward along with the destination emails.# lets forward 2 emails contact@mydomain.com myself@gmail.com sales@mydomain.com myself@gmail.comThe first email is the address on which postfix shall receive emails, and the second is the address where postfix would forward the emails.The mail can be forwarded to multiple destinationscontact@mydomain.com myself@gmail.com mystaff@gmail.comTo catch and forward emails to any address for a given domain, use the following notation# forward all emails @mydomain.com myself@gmail.com mystaff@gmail.comAfter entering the forwarding rules, save the file and close it. Then run the following commands for the new settings to take effectUpdate the postfix lookup table$ postmap /etc/postfix/virtualReload postfix configuration$ sudo /etc/init.d/postfix reload # or $ sudo service postfix reloadCheck with the postconf command that the domain aliases and alias file have been setup properly.$ postconf -n | grep virtual virtual_alias_domains = mydomain.com myanotherdomain.com virtual_alias_maps = hash:/etc/postfix/virtual root@localhost:~#Test it now
Now try sending an email from somewhere outside the world, to the address on your domain, and you should see the same mail forwarded to the gmail account.->
Comments