Set up Postfix to Relay Mail to an External SMTP Server on CentOS 6

Part 5 of setting up a Linux home lab environment with VirtualBox. Check this blog post for more info.

Postfix is a free and open-source mail transfer agent (MTA) that routes and delivers electronic mail.


Software used in this article:

  1. CentOS 6.7
  2. Postfix 2.6.6

Install Postfix

Install Postfix:

# yum install -y postfix cyrus-sasl-plain

In case Sendmail is installed, erase it:

# yum erase -y sendmail*

Open /etc/postfix/ for editing and configure the following:

smtpd_banner = $myhostname ESMTP
inet_interfaces = all
inet_protocols = ipv4

relayhost = []:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CApath = /etc/ssl/certs
smtp_use_tls = yes

mynetworks =,
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
#mydestination = $myhostname, localhost.$mydomain, localhost
unknown_local_recipient_reject_code = 550
debug_peer_level = 2
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no

Create /etc/postfix/sasl_passwd file and add the authentication details of the external SMTP server:

[]:587 [email protected]:passwd

Prevent non-root access:

# chmod 0600 /etc/postfix/sasl_passwd

Create a database file:

# postmap sasl_passwd

Restart Postfix service:

# /etc/init.d/postfix restart

Iptables will be configured via Puppet. The line below is used for the time being only:

# iptables -A INPUT -s -p tcp -m state --state NEW --dport 25 -j ACCEPT


Check logs:

# tail /var/log/messages
# tail /var/log/maillog

4 thoughts on “Set up Postfix to Relay Mail to an External SMTP Server on CentOS 6

Leave a Reply

Your email address will not be published. Required fields are marked *