How to Install Postfix on CentOS 6



Postfix is an open source Mail Transfer Agent that is used to route and deliver electronic email. It attempts to be fast, easy in administering and more secure.

In this tutorial, you will learn how to install Postfix on CentOS 6. We will be using a server named Cyrus which helps in organizing the mail itself.

Installing Postfix and Cyrus


The installation of postfix and Cyrus server on to your virtual private server can be done using the yum installer. Here is how it is done:

sudo yum install postfix


sudo yum install cyrus-sasl
sudo yum install cyrus-imapd

You may be asked to confirm the installation. You need to type in yes when it prompts each time. When all the required components are downloaded completely, the postfix and Cyrus will be installed on your virtual server.


Configuring Postfix


Now that you have it installed, we will get down to configuring.

Open up the Postfix mail configuration file

sudo vi /etc/postfix/

This file is usually detailed and you can get all the information for setting up the program and running it on your VPS.

For doing a quick set up, you may copy the following lines to your Postfix’s main configuration file. Here, I have used, myhostname and for domain name and hostname. You have to replace them with actual values.

Once you update the required fields, your configuration file will almost look similar to this:

soft_bounce             = no
queue_directory         = /var/spool/postfix
command_directory       = /usr/sbin
daemon_directory        = /usr/libexec/postfix
mail_owner              = postfix 

# The default_privs parameter specifies the default rights used by
# the local delivery agent for delivery to external file or command.
# These rights are used in the absence of a recipient user context.
#default_privs = nobody 
myhostname              = 
mydomain                = 
mydestination           = $myhostname, localhostunknown_local_recipient_reject_code = 550 
mynetworks_style        = host
mailbox_transport       = lmtp:unix:/var/lib/imap/socket/lmtp
local_destination_recipient_limit       = 300
local_destination_concurrency_limit     = 5

virtual_alias_maps      = hash:/etc/postfix/virtual 
header_checks           = regexp:/etc/postfix/header_checks
mime_header_checks      = pcre:/etc/postfix/body_checks
smtpd_banner            = $myhostname 
debug_peer_level        = 2
debugger_command =         PATH=/bin:/usr/bin:/usr/bin:/usr/X11R6/bin         xxgdb $daemon_directory/$process_name $process_id & sleep 5 
sendmail_path           = /usr/sbin/sendmail.postfix
newaliases_path         = /usr/bin/newaliases.postfix
mailq_path              = /usr/bin/mailq.postfix
setgid_group            = postdrop
html_directory          = no
manpage_directory       = /usr/share/man
sample_directory        = /usr/share/doc/postfix-2.3.3/samples
readme_directory        = /usr/share/doc/postfix-2.3.3/README_FILES 

smtpd_sasl_auth_enable          = yes
smtpd_sasl_application_name     = smtpd
smtpd_recipient_restrictions    = 

smtpd_sasl_security_options     = noanonymous
smtpd_sasl_local_domain         = broken_sasl_auth_clients        = yes 
smtpd_helo_required             = yes


Setting Up Postfix


To finalize the configuration and set up, you need two more steps to execute.

In the above code, you can see that we have added virtual aliases as virtual_alias_maps:

virtual_alias_maps      = hash:/etc/postfix/virtual

Open up that file:

sudo vi /etc/postfix/virtual

You need to delete all the text in that file and replace them with the given line:

[email protected]   user\

You should substitute the actual user name and domain name in the above mentioned lines.

Save and exit the file.

Now, we are going to set up a database for the postfix to work.

Type in the following command at your terminal:

postmap /etc/postfix/virtual

This command will turn that virtual file into a look-up table and the database will be created for postfix.

Finish up by creating another file that is required by postfix before it starts sending anything out.

touch /etc/postfix/body_checks


Configuring Cyrus


Now that we are done with postfix, we can move on to configure Cyrus.

For that, open up the file /etc/sasl2/smtpd.conf


sudo vi /etc/sasl2/smtpd.conf

Update the file with the following lines of code:

pwcheck_method: auxprop
auxprop_plugin: sasldb

Save and exit the file.

Now, open up the configuration file:

sudo vi /etc/imapd.conf

Delete all the content present in the file and add the following lines to it. Make sure you have replaced required fields such as domain name and server name to match your proper values.

The configuration file should look like this:

virtdomains:        userid
configdirectory:    /var/lib/imap
partition-default:  /var/spool/imap
admins:                    cyrus
sievedir:           /var/lib/imap/sieve
sendmail:           /usr/sbin/sendmail.postfix
hashimapspool:             true
allowanonymouslogin: no
allowplaintext:            yes
sasl_pwcheck_method: auxprop
sasl_mech_list:            CRAM-MD5 DIGEST-MD5 PLAIN
tls_cert_file:             /etc/pki/cyrus-imapd/cyrus-imapd.pem
tls_key_file:       /etc/pki/cyrus-imapd/cyrus-imapd.pem
tls_ca_file:        /etc/pki/tls/certs/ca-bundle.crt 
autocreatequota:           -1
createonpost:              yes
autocreateinboxfolders:           spam
autosubscribeinboxfolders: spam

Save and exit the file.


Install a Mail Client


You already have Postfix and Cyrus which will handle all your electronic mails. Now, we need to install a mail client for sending messages.

There are plenty of mail clients available today and we will be using MailX in this tutorial.

Install the mail client using yum:

yum install mailx

You will be prompted to confirm the installation. Once you agree, the mail x will be installed.

Now, to verify the whole set up type the following into your terminal to send a mail:

mail [email protected]

Make sure you have replaced the email with your correct one.

You will be prompted to enter the subject lines and the subsequent lines. Once you are done entering details, press enter and type in a period (.) to send the mail.

[[email protected] ~]# mail [email protected]
Subject: Hello
This is a test message.


The mail will be sent only when you press enter and type period.

Verify the email and you are all set to use postfix on your virtual private server to send mails.


support2 has written 111 articles

Leave a Reply