xFusionCorp Industries has planned to set up a common email server in Stork DC. After several meetings and recommendations they have decided to use postfix as their mail transfer agent and dovecot as an IMAP/POP3 server. We would like you to perform the following steps:
- Install and configure
postfixonStork DCmail server. - Create an email account
anita@stratos.xfusioncorp.comidentified by8FmzjvFU6S. - Set its mail directory to
/home/anita/Maildir. - Install and configure
dovecoton the same server.
Understanding the Components
Postfix
Postfix is a Mail Transfer Agent responsible for routing and delivering email. It handles SMTP connections, accepts incoming mail, and delivers it to local mailboxes or relays it to other servers. Postfix is known for its security, performance, and ease of administration.
Dovecot
Dovecot is an IMAP and POP3 server that allows users to access their email. It handles authentication and provides access to mailboxes stored on the server. Dovecot supports various mailbox formats, including Maildir and mbox.
Maildir Format
Maildir stores each email as a separate file in a directory structure. This format is more reliable than mbox because it avoids file locking issues and supports concurrent access. The structure consists of three subdirectories: cur for current messages, new for newly delivered messages, and tmp for temporary files during delivery.
Prerequisites
Before beginning, ensure the following are available:
- Access to the mail server with root or sudo privileges
- The mail server hostname and domain information
- Network connectivity between the mail server and other infrastructure components
Server Details for This Tutorial
| Detail | Value |
|---|---|
| Server | stmail01.stratos.xfusioncorp.com |
| User | groot |
| Password | Gr00T123 |
| Email Address | anita@stratos.xfusioncorp.com |
| Email Password | 8FmzjvFU6S |
| Mail Directory | /home/anita/Maildir |
Installing Postfix
Connect to the mail server and switch to root.
# Password: Gr00T123
ssh groot@stmail01
sudo su -
Install Postfix using the system package manager.
yum install postfix -y
The installation includes Postfix and its dependencies. Postfix version 3.5.25 is installed on CentOS Stream 9.
Configuring Postfix
Edit the main Postfix configuration file at /etc/postfix/main.cf.
vi /etc/postfix/main.cf
Add or modify the following parameters:
myhostname = stmail01.stratos.xfusioncorp.com
mydomain = stratos.xfusioncorp.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 172.16.238.0/24, 127.0.0.0/8
home_mailbox = Maildir/
Parameter Explanation
| Parameter | Purpose |
|---|---|
| myhostname | Fully qualified domain name of the mail server |
| mydomain | Domain name used for email addresses |
| myorigin | Domain used for outgoing mail |
| inet_interfaces | Network interfaces Postfix listens on |
| mydestination | Domains for which Postfix accepts mail |
| mynetworks | Trusted networks for relaying |
| home_mailbox | Mailbox format and location |
The home_mailbox = Maildir/ setting is critical. It tells Postfix to deliver mail in Maildir format within the user's home directory.
Starting and Enabling Postfix
Start the Postfix service and enable it to start on boot.
systemctl start postfix
systemctl enable postfix
systemctl status postfix
Verify that Postfix is running and listening on port 25.
ss -tlnp | grep :25
Creating the Email Account
Create a system user for the email account. The username becomes the local part of the email address.
useradd anita
passwd anita
When prompted, enter the password 8FmzjvFU6S twice.
Verify the user was created.
id anita
Creating the Maildir Directory
Create the Maildir structure in the user's home directory.
mkdir -p /home/anita/Maildir/{cur,new,tmp}
Set the correct ownership so the user can access the mailbox.
chown -R anita:anita /home/anita/Maildir
Verify the directory structure.
ls -la /home/anita/Maildir/
The output should show three subdirectories: cur, new, and tmp, all owned by anita.
Installing Dovecot
Install Dovecot using the system package manager.
yum install dovecot -y
Dovecot version 2.3.16 is installed along with its dependencies, including clucene-core and libexttextcat.
Configuring Dovecot
Dovecot configuration is split across several files in the /etc/dovecot/ directory. Each file controls a specific aspect of the server.
Enable IMAP and POP3 Protocols
Edit /etc/dovecot/dovecot.conf.
vi /etc/dovecot/dovecot.conf
Set the protocols line to enable both IMAP and POP3.
protocols = imap pop3
Set the Mail Location
Edit /etc/dovecot/conf.d/10-mail.conf.
vi /etc/dovecot/conf.d/10-mail.conf
Set the mail location to match the Postfix Maildir setting.
mail_location = maildir:~/Maildir
This must match the home_mailbox setting in Postfix for mail delivery to work correctly.
Configure Authentication
Edit /etc/dovecot/conf.d/10-auth.conf.
vi /etc/dovecot/conf.d/10-auth.conf
Set the authentication parameters.
disable_plaintext_auth = yes
auth_mechanisms = plain login
Configure the Auth Service Socket
Edit /etc/dovecot/conf.d/10-master.conf.
vi /etc/dovecot/conf.d/10-master.conf
Configure the auth service socket for Postfix integration.
service auth {
unix_listener auth-userdb {
mode = 0660
user = postfix
group = postfix
}
}
This allows Postfix to authenticate users through Dovecot.
Starting and Enabling Dovecot
Start the Dovecot service and enable it to start on boot.
systemctl start dovecot
systemctl enable dovecot
systemctl status dovecot
Verify that Dovecot is running and listening on ports 110 and 143.
ss -tlnp | grep -E ":110|:143"
Verification
Check Service Status
systemctl is-active postfix
systemctl is-enabled postfix
systemctl is-active dovecot
systemctl is-enabled dovecot
All services should return active and enabled.
Check Listening Ports
ss -tlnp | grep -E ":25|:110|:143"
Expected output shows Postfix on port 25 and Dovecot on ports 110 and 143.
Check User and Maildir
id anita
ls -la /home/anita/Maildir/
The user should exist with the correct UID, and the Maildir should contain cur, new, and tmp directories.
Test SMTP
telnet localhost 25
The connection should succeed and show the Postfix banner.
Test POP3
telnet localhost 110
user anita
pass 8FmzjvFU6S
The authentication should succeed.
Troubleshooting
Postfix Warnings About Overriding
When configuration lines are duplicated, Postfix issues warnings. Remove duplicate entries from /etc/postfix/main.cf and restart Postfix.
Dovecot Fails to Start
Check the Dovecot logs for errors.
journalctl -u dovecot -n 50
doveadm log find
Mail Not Delivered
Verify that the home_mailbox setting in Postfix matches the mail_location setting in Dovecot. Both should point to Maildir.
Authentication Failures
Ensure the auth service socket is configured correctly in 10-master.conf with the postfix user and group.
Port Conflicts
Ensure no other service is using ports 25, 110, or 143.
ss -tlnp | grep -E ":25|:110|:143"
Configuration Summary
| Component | Configuration |
|---|---|
| Mail Server | stmail01.stratos.xfusioncorp.com |
| Email Address | anita@stratos.xfusioncorp.com |
| Password | 8FmzjvFU6S |
| Mail Directory | /home/anita/Maildir |
| Postfix Port | 25 |
| Dovecot IMAP Port | 143 |
| Dovecot POP3 Port | 110 |
| Mailbox Format | Maildir |
Best Practices
Use Maildir Format
Maildir is more reliable than mbox for concurrent access and avoids file locking issues.
Keep Postfix and Dovecot Settings Consistent
The mail location in Dovecot must match the home_mailbox setting in Postfix.
Enable Only Required Protocols
Enable only the protocols that are needed. If POP3 is not required, disable it.
Secure Authentication
Use TLS for authentication when possible. Configure Dovecot to use SSL/TLS certificates.
Monitor Logs
Regularly check mail logs for errors and delivery issues.
tail -f /var/log/maillog
Regular Backups
Back up mail directories and configuration files regularly.
Conclusion
Setting up a mail server with Postfix and Dovecot provides a reliable and secure email solution for enterprise environments. Postfix handles mail transfer and delivery, while Dovecot provides IMAP and POP3 access to mailboxes. The Maildir format ensures reliable mail storage.
The key steps are installing both packages, configuring Postfix to deliver mail in Maildir format, creating user accounts with the correct mail directory structure, and configuring Dovecot to access those mailboxes. Verification of services, ports, and user accounts ensures the setup is complete and functional.












