Installation: Email Server
Requirements
- A server running Rocky Linux
- Knowledge of the command-line and text editors
- Background on email infrastructure
Introduction
*This guide is incomplete.*
The installation, configuration, and use of an email server requires multiple applications working in tandem as well as the management of DNS records, antivirus, email blacklists, port management. This guide will demonstrate the requirements and steps needed to:
- Install a Postfix SMTP server
- Install a Dovecot IMAP server with TLS encryption
- Manage email domains an mailboxes with PostfixAdmin
- Creating SPF, DKIM, and DMARC records
- Block spam and use a reflector service (if needed)
- Port-forwarding to your email server
Much of this guide was taken from guide1 written by Xiao Guoan with modifications to fit the firm's needs.This guide does not educate or provide opinions on service providers for intermediate processes required for a successful deployment of this email server or mail transport agent. For potential errors in the setup process refer to the footnotes.
Prior to the intallation of software or setup, developers may seek to set or alter the server's hostname. The hostname can be viewed by the command:
hostname -f
To alter the hostname run the command:
sudo hostnamectl set-hostname <fully-qualified-domain-name>
An example of a full qualified domain name is mail.yourdomain.com
Postfix
Postfix - Installation
Install the SMTP server :
sudo dnf updatesudo dnf install postfix postfix-mysql -y
Start the SMTP server :
postfix start
To confirm the server is running, run:
sudo ss -lnpt | grep master
Postfix - Configuration
Install firewalld if it is not installed.
dnf install firewalld
Enable and start the firewall.
systemctl enable firewalldsystemctl start firewalld
Open the related ports to the SMTP (port 25) service.
firewall-cmd --permanent --add-port=25/tcp
Reload the firewall
firewall-cmd --reload
Modify the postconf configuration file to allow for larger attachments.
sudo postconf -e message_size_limit=25000000
Modify the postconf configuration file to allow for larger inboxes.
sudo postconf -e mailbox_size_limit=1000000000
After changes are made to the Postfix configure the service must be restarted.
sudo systemctl restart postfix
In many cases the hostname of the server needs to be different from teh email server. To set the hostname of the of the Postfix server modify the main configuration file.
sudo vi /etc/postfix/main.cf
Modify the variable 'myhostname' to reflect you domain.
myhostname = mail.yourdomain.com
If the mail server doesn’t have a public IPv6 address, it’s better to disable IPv6 in Postfix to prevent unnecessary IPv6 connections. Simply run the following command to disable IPv6 in Postfix.
sudo postconf -e "inet_protocols = ipv4"
If ever prompted to update the Postfix configuration, maintain the 'No configuration' status.
To send emails from a desktop email client, enable the submission service of Postfix to be able to send email through the Postfix SMTP server. Edit the master.cf file.
sudo vi /etc/postfix/master.cf
To send emails from a desktop email client, enable the submission service of Postfix giving it the ability to send email through the Postfix SMTP server. Edit the master.cf file.
'submission' allows for submission on port 587.
submission inet n - y - - smtpd -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt -o smtpd_tls_wrappermode=no -o smtpd_sasl_auth_enable=yes -o smtpd_relay_restrictions=permit_sasl_authenticated,reject -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject -o smtpd_sasl_type=dovecot -o smtpd_sasl_path=private/auth
'smtps' allows for submission on port 465.
smtps inet n - y - - smtpd -o syslog_name=postfix/smtps -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes -o smtpd_relay_restrictions=permit_sasl_authenticated,reject -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject -o smtpd_sasl_type=dovecot -o smtpd_sasl_path=private/auth
Dovecot
Dovecot - Installation
Dovecot is an imap and pop3 server. This allows for the email and folder retrival from the email server.IMAP is the prefered protocol.
dnf install dovecot dovecot-mysql dovecot-pigeonhole
Edit the Dovecot configuration file to allow for the imap protcol.
sudo vi /etc/dovecot/dovecot.conf
Add the line allowing dovecot to use the imap protocol
protocols = imap lmtp
Modify the configuration to change the mailbox location from mbox to Maildir. The Dovecot to store emails in Maildir format, by default, Postfix uses its built-in local delivery agent to move inbound emails to the message store. It will be saved in mbox. We need to configure Postfix to pass incoming emails to Dovecot, via the LMTP protocol, which is a simplified version of SMTP, so incoming emails will saved in Maildir format by Dovecot. LMTP allows for a highly scalable and reliable mail system. It also allows us to use the sieve plugin to filter inbound messages to different folders.
sudo vi /etc/dovecot/conf.d/10-mail.conf
Uncomment the lines.
mail_location = maildir:~/Maildirmail_location = mbox:~/mail:INBOX=/var/mail/%umail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
Add dovecot to the mail group so that Dovecot can read the inbox.
usermod -a -G mail dovecot