Using CentOS as Internal Mail Relay Server

This note provides steps in building a CentOS server to act as an internal mail relay gateway for Internet bound emails. All internet emails are relayed through the ISP account using ISP mail server as Smart host.

These steps were tested on CentOS 5.3 using Networksolutions.com mail relay account. Networksolutions like many other paid services require senders to authenticate before they can relay email through their servers.

1. Download and install Postfix using Yum

yum install postfix

2. Download and install system-switch-mail to change MTA from Sendmail (default) to newly installed Postfix

yum install system-switch-mail

3. Create /etc/postfix/sasl_passwd containing password for the mail server relay account:

smtp.yourdomain.com      username@yourdomain.com:password

4. Edit /etc/postfix/main.cf and add the following lines to the end of file:

relayhost = [smtp.yourdomain.com]

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options =
smtp_generic_maps = hash:/etc/postfix/generic

Note: It is assumed that your ISP allows you to connect to port 25 on the host smtp.yourdomain.com if this is not the case (for example your ISP allows only higher numbered ports like 2525) then you can change the relayhost entry to something like this:

relayhost = [smtp.yourdomain.com]:2525

5. Edit /etc/postfix/generic and add the following line to the end of file:

@yourmachinename.localdomain username@yourdomain.com

The generic translation is needed because the Default machine names are something like yourmachinename.localdomain (or it could be localhost.localdomain if you have not configured the hostname) and Sender address will be username@yourmachinename.localdomain (such sender addresses are rejected as SPAM).

You have to tell postfix to change the Sender address from something like root@yourmachinename.localdomain to username@yourdomain.com.

6. Generate hash for /etc/postfix/generic:

postmap hash:/etc/postfix/generic

7. Secure sasl_passwd file as it contains credentials:

chown root:root /etc/postfix/sasl_passwd

chmod 600 /etc/postfix/sasl_passwd

8. Generate hash for /etc/postfix/sasl_passwd:

postmap hash:/etc/postfix/sasl_passwd
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply