How to Install Postfix on CentOS 6

Introduction

 

Postfix is one of the popular  open source Mail Transfer Agent  used to route and deliver electronic email. It is popular as it seems  to be fast, easy to administer  and very secure.

This article helps you to learn how to install Postfix on CentOS 6 in  a server named Cyrus which helps in organizing the mail itself.

Installing Postfix and Cyrus

 

To install postfix:

sudo yum install postfix

 

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

Make sure to enter yes to confirm installation when it prompts each time.

Configuring Postfix

 

 

configuration of postfix:

main.cf is the file where almost all the configuration are done as given below:

sudo vi /etc/postfix/main.cf

For a simple setup , you may copy the following lines to your Postfix’s main configuration file. Here, I have used example.com, myhostname and mail.example.com for domain name and hostname. Make sure to replace them of your own.

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.
# DO NOT SPECIFY A PRIVILEGED USER OR THE POSTFIX OWNER.
#
#default_privs = nobody 
myhostname              = mail.example.com 
mydomain                = example.com 
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
recipient_delimiter=+ 

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    = 
permit_sasl_authenticated,
                                  permit_mynetworks,
                                  reject_unauth_destination,
                                  reject_invalid_hostname,
                                  reject_non_fqdn_hostname,
                                  reject_non_fqdn_sender,
                                  reject_non_fqdn_recipient,
                                  reject_unknown_sender_domain,
                                  reject_unknown_recipient_domain,
 
                                 reject_unauth_pipelining,
                                  reject_rbl_client zen.spamhaus.org,
                                  reject_rbl_client bl.spamcop.net,
                                  reject_rbl_client dnsbl.njabl.org,
                                  reject_rbl_client dnsbl.sorbs.net,
   
                               permit 

smtpd_sasl_security_options     = noanonymous
smtpd_sasl_local_domain         = broken_sasl_auth_clients        = yes 
smtpd_helo_required             = yes

 

Setting Up Postfix

 

you  need two execute two more steps to execute for the final configuration of postfix as shown below:

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

virtual_alias_maps      = hash:/etc/postfix/virtual

Go to configuration fiel :

sudo vi /etc/postfix/virtual

Make sure  to delete all the text in that file and replace them with the given line:

[email protected]   user\@example.com

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

Save and exit the file.

After configuration is done we need  to set up a database for the postfix to work which can be done as given below:

postmap /etc/postfix/virtual

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

Finally, by creating another file that is required by postfix before it starts sending anything out.

touch /etc/postfix/body_checks

 

Configuring Cyrus

 

After postfix is done we can configure cyrus as given below:

edit the file with your favourite text editor  /etc/sasl2/smtpd.conf

 

sudo vi /etc/sasl2/smtpd.conf

ensure to update the file  as shown below:

pwcheck_method: auxprop
auxprop_plugin: sasldb
mech_list: PLAIN LOGIN CRAM-MD5 DIGEST-MD5

Save and exit the file.

furthermore, open up the configuration file:

sudo vi /etc/imapd.conf

You can replace the entire file with the configuration given below but make sure to replace domain name of your own as given below:

 

virtdomains:        userid
defaultdomain:             example.com
servername:         example.com
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

To handle your electronic mails you will need an agent as you already have Postfix and Cyrus installed . Mail client is really handy on this scenario.

You can find pleanty of other mail client however we are installing the mail client using yum:

yum install mailx

You can enter ‘Y’ for the confirmation while installing it. after it has been successfully installed

we can verify the entire set up bye hitting the command given below at your terminal to send an email:

mail [email protected]

Ensure to replace the email with the correct one whom you want to sent to.

You will be asked 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 as shown below:

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

 .
EOT

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

 

 

KB Admin has written 46 articles