Detailed steps for installing and deploying mail server of Postfix under CentOS 7.2

  • 2020-06-03 09:08:01
  • OfStack

This article mainly introduces the installation and deployment of mail server (Postfix) in CentOS 7.2. It is Shared for your reference and study. Here is a detailed introduction:

Postfix is an E-mail server created by Wietse Venema, a Dutch researcher at the IBM Watson Research Center (T.J. Watson Research Center) to improve the sendmail E-mail server. It first appeared in the late 1990s as an open source software.

Note: All of the following configuration names are configured according to the host's hostname variable, and if hostname is changed, the certificate will need to be regenerated.

Generate the ssl certificate

1. Script code to generate the certificate

Generate a certificate named hostname and enter the same password four times after running the script (password must contain Numbers and letters)

rm -rf $(hostname).*

openssl genrsa -des3 -out $(hostname).key 1024


openssl req -new -subj $SUBJECT -key $(hostname).key -out $(hostname).csr

mv $(hostname).key $(hostname).origin.key

openssl rsa -in $(hostname).origin.key -out $(hostname).key

openssl x509 -req -days 3650 -in $(hostname).csr -signkey $(hostname).key -out $(hostname).crt

cp $(hostname).crt /etc/pki/tls/certs/$(hostname).crt
cp $(hostname).key /etc/pki/tls/certs/$(hostname).key

echo "the key path:/etc/pki/tls/certs/$(hostname).key"
echo "the crt path:/etc/pki/tls/certs/$(hostname).crt"

rm -rf $(hostname).*

Postfix installation and configuration

The installation

yum -y install postfix


vim /etc/postfix/

# line 75: uncomment and specify hostname
myhostname = $(hostname)

# line 83: uncomment and specify domain name
mydomain =

# line 99: uncomment
myorigin = $mydomain

# line 116: change
inet_interfaces = all

# line 164: add
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

# line 264: uncomment and specify your local network
mynetworks =,

# line 419: uncomment (use mailboxdir)
home_mailbox = mailbox/

# line 574: add
smtpd_banner = $myhostname ESMTP

#  Appends the following to the end of the profile 

# limit an email size for 10M
message_size_limit = 10485760

# limit a mailbox for 1G
mailbox_size_limit = 1073741824

# for SMTP-Auth
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject
smtpd_use_tls = yes
smtpd_tls_cert_file = /etc/pki/tls/certs/$(hostname).crt
smtpd_tls_key_file = /etc/pki/tls/certs/$(hostname).key
smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scache

vim /etc/postfix/

# line 26-28: uncomment
smtps  inet n  -  n  -  -  smtpd
 -o syslog_name=postfix/smtps
 -o smtpd_tls_wrappermode=yes

Dovecot installation and configuration

The installation

yum -y install dovecot


vim /etc/dovecot/dovecot.conf

# line 24: uncomment
protocols = imap pop3 lmtp
# line 30: uncomment and change ( if not use IPv6 )
listen = *

vim /etc/dovecot/conf.d/10-auth.conf

# line 10: uncomment and change ( allow plain text auth )
disable_plaintext_auth = no
# line 100: add
auth_mechanisms = plain login

vim /etc/dovecot/conf.d/10-mail.conf

# line 30: uncomment and add
mail_location = maildir:~/Maildir

vim /etc/dovecot/conf.d/10-master.conf

# line 96-98: uncomment and add like follows
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
 mode = 0666
 user = postfix
 group = postfix

vim /etc/dovecot/conf.d/10-ssl.conf

# line 8: change
ssl = yes
# line 14,15: specify certificates
ssl_cert = </etc/pki/tls/certs/$(hostname).crt
ssl_key = </etc/pki/tls/certs/$(hostname).key


yum -y install postfix

Mail log report pflogsumm

The installation

yum -y install postfix

To view

yum -y install postfix

AM regularly sends mail log summaries to root every day at 1:00

crontab -e
00 01 * * * perl /usr/sbin/pflogsumm -e -d yesterday /var/log/maillog | mail -s 'Logwatch for Postfix' root


Related articles: