Skip to content

Install posix mail server

Monte, I’ve cleaned up and organized the instructions for better readability and clarity. Here’s the structured process:


Prerequisites

Before starting, ensure you have: - A CentOS 9 server. - A non-root user with sudo privileges. - A valid domain name configured with proper DNS records (MX and A records).


Step 1: Install and Configure Postfix

Postfix is a free and open-source mail transfer agent (MTA) used for routing and delivering emails.

Install Postfix

sudo dnf install -y postfix

Configure Postfix

Open the main configuration file:

sudo nano /etc/postfix/main.cf

Modify the following parameters:

myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 127.0.0.0/8
home_mailbox = Maildir/
smtpd_username = $myhostname ESMTP

Enable and Start Postfix

sudo systemctl enable postfix
sudo systemctl start postfix

Step 2: Create Email Account

Add the User Ammar

sudo useradd -m -s /bin/bash ammar

Set User Password

echo 'ammar:dCV3szSGNA' | sudo chpasswd

Create Mail Directory

If maildirmake is unavailable, manually create Maildir format:

mkdir -p /home/ammar/Maildir/{cur,new,tmp}

Verify setup:

ls -l /home/ammar/Maildir

Set correct permissions:

sudo chown -R ammar:ammar /home/ammar/Maildir

Step 3: Install and Configure Dovecot

Dovecot is an open-source IMAP and POP3 server.

Install Dovecot

sudo dnf install -y dovecot

Enable IMAP and POP3

Edit configuration:

sudo nano /etc/dovecot/dovecot.conf

Add:

protocols = imap pop3

Configure Mail Location

Edit:

sudo nano /etc/dovecot/conf.d/10-mail.conf

Set:

mail_location = maildir:~/Maildir

Configure Authentication

Edit:

sudo nano /etc/dovecot/conf.d/10-auth.conf

Modify:

disable_plaintext_auth = no
auth_mechanisms = plain login

Enable and Start Dovecot

sudo systemctl enable dovecot
sudo systemctl start dovecot

Step 4: Configure Firewall

Allow necessary ports:

sudo firewall-cmd --add-service=smtp --permanent
sudo firewall-cmd --add-service=pop3 --permanent
sudo firewall-cmd --add-service=imap --permanent
sudo firewall-cmd --reload

Step 5: Testing the Setup

Verify Postfix

Send a test email:

echo "Test email from Postfix" | mail -s "Test Postfix" your-email@example.com

Verify Dovecot

Connect using telnet:

telnet your-server-ip 110

Try logging in with a user account.


Everything is now organized for easy execution. Let me know if you need any refinements! 🚀