DEV Community

Cover image for 14.Linux Postfix Mail Server
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

14.Linux Postfix Mail Server

Lab Information

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:

  1. Install and configure postfix on Stork DC mail server.

  2. Create an email account anita@stratos.xfusioncorp.com identified by LQfKeWWxWD.

  3. Set its mail directory to /home/anita/Maildir.

  4. Install and configure dovecot on the same server.

Lab Solutions

🧭 Part 1: Lab Step-by-Step Guidelines

Objective

On the Mail Server (stmail01):

Install postfix

Create email user anita

Configure mailbox location

Install and configure dovecot

Server details:

Server User
stmail01 groot

1️⃣ Login to Jump Host

ssh thor@jump_host.stratos.xfusioncorp.com
Enter fullscreen mode Exit fullscreen mode

Password:

mjolnir123

2️⃣ Connect to Mail Server

ssh groot@stmail01
Enter fullscreen mode Exit fullscreen mode

Password:

Gr00T123

3️⃣ Switch to Root

sudo -i
Enter fullscreen mode Exit fullscreen mode

4️⃣ Install Postfix

yum install -y postfix
Enter fullscreen mode Exit fullscreen mode

Start and enable it:

systemctl start postfix
systemctl enable postfix
Enter fullscreen mode Exit fullscreen mode

5️⃣ Create User anita

useradd anita

# Set password:

passwd anita

Enter:

LQfKeWWxWD
Enter fullscreen mode Exit fullscreen mode

6️⃣ Create Mail Directory

mkdir -p /home/anita/Maildir

# Set ownership:

chown -R anita:anita /home/anita/Maildir
Enter fullscreen mode Exit fullscreen mode

7️⃣ Configure Postfix Mailbox Location

Edit postfix configuration:

vi /etc/postfix/main.cf

Add this line at the end:

home_mailbox = Maildir/

Save:

ESC
:wq

# Restart postfix:

systemctl restart postfix
Enter fullscreen mode Exit fullscreen mode

8️⃣ Install Dovecot

yum install -y dovecot
Enter fullscreen mode Exit fullscreen mode

9️⃣ Configure Dovecot Mail Location

Edit configuration:

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

Find:

mail_location =

Change to:

mail_location = maildir:~/Maildir

Save and exit.
Enter fullscreen mode Exit fullscreen mode

🔟 Start and Enable Dovecot

systemctl start dovecot
systemctl enable dovecot
Enter fullscreen mode Exit fullscreen mode

1️⃣1️⃣ Verify Services

systemctl status postfix
systemctl status dovecot
Enter fullscreen mode Exit fullscreen mode

Both should show:

active (running)


🧠 Part 2: Simple Explanation (Beginner Friendly)

What this lab builds

You are setting up a basic Linux mail server.

Two main components are required:

Component Purpose
Postfix Mail transfer agent (send mail)
Dovecot Mailbox server (read mail)

How Email Flow Works

Example:

User sends mail → Postfix
Postfix stores mail → Maildir
User reads mail → Dovecot

Architecture:

Client

Postfix (SMTP server)

Maildir storage

Dovecot (IMAP / POP3)
Why Maildir is used

Mail storage formats:

Format Description
mbox one large file
Maildir one file per email

Maildir is preferred because it is:

faster

safer

better for concurrent access

Mail directory:

/home/anita/Maildir
What home_mailbox = Maildir/ does

This tells postfix:

Store user mail inside Maildir folder

Example:

/home/anita/Maildir/new
/home/anita/Maildir/cur
/home/anita/Maildir/tmp
Why we install Dovecot

Postfix cannot read email.

It only delivers mail.

Dovecot allows users to access email using:

Protocol Port
IMAP 143
POP3 110


Resources & Next Steps
📦 Full Code Repository: KodeKloud Learning Labs
📖 More Deep Dives: Whispering Cloud Insights - Read other technical articles
💬 Join Discussion: DEV Community - Share your thoughts and questions
💼 Let's Connect: LinkedIn - I'd love to connect with you

Credits
• All labs are from: KodeKloud
• I sincerely appreciate your provision of these valuable resources.

Top comments (0)