We'll set up a simple mail server using Postfix for sending emails and Dovecot for receiving and managing them.
Step 1: Update the System
Update the package index:
sudo apt update
Step 2: Install Postfix
Install Postfix:
sudo apt install postfix -y
During installation:
- Select Internet Site when prompted.
- Enter your domain or server's hostname.
Verify the installation:
sudo systemctl status postfix
Step 3: Install Dovecot
Install Dovecot:
sudo apt install dovecot-core dovecot-imapd -y
Start and enable Dovecot:
sudo systemctl start dovecot
sudo systemctl enable dovecot
Verify the installation:
sudo systemctl status dovecot
Step 4: Configure Postfix
Open the Postfix configuration file:
sudo nano /etc/postfix/main.cf
Update or add the following lines:
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, $mydomain
home_mailbox = Maildir/
Save the file and restart Postfix:
sudo systemctl restart postfix
Step 5: Configure Dovecot
Enable the Maildir format:
sudo nano /etc/dovecot/conf.d/10-mail.conf
Find the line mail_location
and update it:
mail_location = maildir:~/Maildir
Save the file and restart Dovecot:
sudo systemctl restart dovecot
Step 6: Test the Mail Server
Create a test user for email:
sudo adduser testuser
Send an email to the test user:
echo "Test email body" | mail -s "Test Subject" testuser
Verify the email:
sudo apt install mailutils -y
mail
Log in as testuser
and check the email in the Maildir folder:
su - testuser
cd ~/Maildir
Top comments (0)