Skip to Main Content

Configure a CentOS 6.4 Web Server on Rackspace - Part 5: Postfix Email Forwarding

Postfix is the default mailserver on CentOS. The following tutorial will set up email forwarding for the domains on our server. We will assume that the primary domain on the server is called host.com.

DNS Settings

1. Create an A record for the mailserver, e.g.

mail.host.com

2. Add an MX record to any hosted domains (e.g. mydomain1.com) pointing to mail.host.com with priority 10.

3. Use dig to check the settings (look at ANSWER SECTION)

$ dig mail.host.com @dns1.stabletransit.com

$ dig mydomain1.com mx @dns1.stabletransit.com

iptables

Next, use the GUI to open the SMTP port (port 25) so we can receive connections:

$ sudo system-config-firewall-tui
# open the port for SMTP
$ sudo service iptables restart

We can check the settings:

$ sudo iptables -L
# output should contain the line:
# ACCEPT tcp -- anywhere anywhere tcp dpt:smtp

Postfix

Start Postfix:

$ sudo service postfix start
$ sudo chkconfig postfix on

Open the Postfix config file main.cf:

$ sudo vim /etc/postfix/main.cf

Uncomment or add the following lines:

inet_interfaces = all

relay_domains =

mynetworks = 192.168.0.0/24, 127.0.0.0/8

myhostname = mail.host.com

Finally, add virtual_alias_domains, which is a list of your hosted domains. And add virtual_alias_maps, which is a file that will hold the forwarder-to-address mappings. I'd like a better way to handle this, like we did with mass virtual hosts in httpd.conf, but I haven't had time to figure one out yet:

virtual_alias_domains = mydomain1.com, mydomain2.com
virtual_alias_maps = hash:/etc/postfix/virtual

Then open the virtual file:

$ sudo vim /etc/postfix/virtual

And add each email forwarder:

me@mydomain1.com  me@gmail.com
someone@mydomain2.com  wherever@yahoo.com
# optionally, add a catch-all address for the domain
@mydomain1.com  another@outlook.com

The virtual file could also be built from a database if that suits you needs better.

Finally, reload postfix settings:

# rebuild the forwarder database
$ sudo postmap /etc/postfix/virtual
# restart postfix
$ sudo service postfix restart

Make sure we can connect on port 25:

$ telnet mail.host.com 25
220 mail.host.com ESMTP Postfix
# Press CTRL + ]
telnet > quit 

The email forwarders we created in the virtual file should be working now. Note that the DNS settings at the beginning of the tutorial will take efect in about 5 minutes if your DNS is hosted at Rackspace. Some other DNS providers can take up to 48 hours.

SpamAssassin

One problem with forwarding mail is that your server's IP address reputation will be harmed by forwarding spam messages. Gmail recommends tagging spam using SpamAssassin.

 

Most RecentRSS

ArchiveRSS

March 2016 (1)
January 2016 (1)
September 2015 (1)
May 2015 (1)
April 2015 (1)
March 2015 (1)
February 2015 (2)
January 2015 (5)
September 2014 (2)
August 2014 (4)
July 2014 (1)
March 2014 (1)
November 2013 (3)
September 2013 (3)
July 2013 (6)
June 2013 (1)
May 2013 (1)
March 2013 (2)
February 2013 (3)
January 2013 (4)