Wednesday, December 16, 2015

Foward mail to different domains using Postfix - all domains hosted on same server - external email hosting



I have one server hosting several domains - one main domain and several alias domains.



Domains



main.com
alias1.com
alias2.com



I use the domain name registra's (Gandi.net) email service for the main domain. I would like all emails to the alias domains to be forwarded to the email service for the main one. Which I think means just forward them to @main.com



I'm struggling with Postfix (and maybe DNS?) settings.



DNS



main mx records
fb.mail.gandi.net <-- Gandi's settings - I'm sure they're correct
spool.mail.gandi.net


alias1 mx records
mail.alias1.com

alias2 mx records
mail.alias2.com


All domains have an A/AAAA record for mail.[domain].com which points to the server IP address.




I also have a 4th domain (superdomain.com) which I am using as the server's hostname. It's DNS records look the same as main.com.



Using this page from Postfix - http://www.postfix.org/VIRTUAL_README.html - it looks like I can use virtual alias domains



main.cf settings



myhostname = mail.superdomain.com
mydestination = pluto.superdomain.com localhost.superdomain.com localhost $myhostname localhost.$mydomain
virtual_alias_domains = alias1.com alias2.com
virtual_alias_maps = hash:/etc/postfix/virtual


relay_domains = main.com


virtual file contents



@alias1.com @main.com
@alias2.com @main.com



The settings might look a little odd. I've tried quite a few combinations thus far :-P. The structure of the virtual file comes from the answer to How to redirect all mail from one domain to another in Postfix? [serverfault.com]



Based on the bounce backs from test emails - I seem to be getting "connection refused" results.



Any ideas or tips?


Answer



It was a firewall (iptables) issue! At some point I changed the firewall and completely forgot :-P



For those it might help doing this in the future, the final configuration for doing this was:




main mx records
fb.mail.gandi.net
spool.mail.gandi.net

alias1 mx records
mail.superdomain.com

alias2 mx records
mail.superdomain.com



main.cf settings



myhostname = mail.superdomain.com
mydomain = superdomain.com
mydestination = pluto.superdomain.com, localhost.superdomain.com, localhost
virtual_alias_domains = alias1.com alias2.com


virtual file contents




@alias1.com @main.com
@alias2.com @main.com


Extra firewall/iptables rule



-A INPUT -p tcp -m tcp --dport 25 -j ACCEPT



The gist of the settings is:




  • the mx mail records tell mail servers on the Internet (not yours) which IP address they should send their mail to. Each of the domains had an A record for mail.[domain].com which resolved to the server IP address. I think it could have been left as mail.alias[x].com but it seemed neater to make it mail.superdomain.com as superdomain is conceptually the mail servering domain.

  • mydestination specifies what domains postfix can deliver to on this server - that is, locally

  • virtual_alias_domains specifies where postfix is allowed to forward (alias) mail onto


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...