Postfix and Dovecot Configuration
Installation
hostnamectl set-hostname mail.<domain>.<tld>
yum -y install postfix dovecot
Postfix Configuration
-
Append the following to
/etc/postfix/main.cf
:myhostname = mail.<domain>.<tld>
mydomain = <domain>.<tld>
myorigin = $mydomain
home_mailbox = mail/
mynetworks = 127.0.0.0/8 <domain IP>
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtpd_tls_loglevel = 1
smtpd_tls_key_file = /etc/letsencrypt/live/<domain>.<tld>/privkey.pem
smtpd_tls_cert_file = /etc/letsencrypt/live/<domain>.<tld>/fullchain.pem
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtpd_use_tls=yes
tls_random_source = dev:/dev/urandom
virtual_alias_domains = <domain>.<tld>
virtual_alias_maps = hash:/etc/postfix/virtual
-
Find and uncomment the following lines in
/etc/postfix/main.cf
:#inet_interfaces = localhost
#mydestination = $myhostname, localhost.$mydomain, localhost
-
Append the following lines to
/etc/postfix/master.cf
:submission inet n - n - - smtpd
-o syslog_name=postfix/submission
-o smtpd_sasl_auth_enable=yes
-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject_unauth_destination
-o milter_macro_daemon_name=ORIGINATING
smtps inet n - n - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_sasl_auth_enable=yes
-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject_unauth_destination
-o milter_macro_daemon_name=ORIGINATING
-
Make sure that the following is present in
/etc/postfix/main.cf
:alias_maps = hash:/etc/aliases
-
Edit and add the desired email address to
/etc/postfix/virtual
such as the following:info@<domain>.<tld> admin
webmaster@<domain>.<tld> admin
-
Create a map database:
postmap /etc/postfix/virtual
Dovecot Configuration
-
Find and modify the following lines in
/etc/dovecot/conf.d/10-master.conf
:# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
-
Find and modify the following lines in
/etc/dovecot/conf.d/10-auth.conf
:auth_mechanisms = plain login
-
Find and modify the following lines in
/etc/dovecot/conf.d/10-mail.conf
:mail_location = maildir:~/mail
-
Find and modify the following lines in
/etc/dovecot/conf.d/20-pop3.conf
:pop3_uidl_format = %08Xu%08Xv
-
Find and modify the following lines in
/etc/dovecot/conf.d/10-ssl.conf
:ssl_cert = </etc/letsencrypt/live/<domain>.<tld>/fullchain.pem
ssl_key = </etc/letsencrypt/live/<domain>.<tld>/privkey.pem
Restart and Enable Services
systemctl restart postfix
systemctl enable postfix
systemctl restart dovecot
systemctl enable dovecot
Open Firewall Ports
firewall-cmd --permanent --add-service=smtp
firewall-cmd --permanent --add-port=587/tcp
firewall-cmd --permanent --add-port=465/tcp
firewall-cmd --permanent --add-port=110/tcp
firewall-cmd --permanent --add-service=pop3s
firewall-cmd --permanent --add-port=143/tcp
firewall-cmd --permanent --add-service=imaps
firewall-cmd --reload
Configure DNS
-
Add an
A
record for the mail server:name = mail.<domain>.<tld>`
IP = <mail server IP>
-
Add an
MX
record:Hostname = mail.<domain>.<tld>
Priority = 5
-
Add the following
TXT
records:Name = @
Text = "v=spf1 ip4:<domain IP> ~all"
Name = _dmarc.<domain>.<tld>
Text = v=DMARC1; p=none
-
Add
PTR
record for<domain>.<tld>
-
Finally, test your email at
https://www.mail-tester.com/
Notes on Using Let's Encrypt for SSL
Make sure that Encryption
is set to STARTTLS
when configuring mail clients