How to install mail server on ubuntu 20.04

Installing a mail server on Ubuntu 20.04 involves several steps, including setting up the mail transfer agent (MTA), mail delivery agent (MDA), and mail user agent (MUA). Here's a step-by-step guide to help you install and configure a basic mail server on Ubuntu 20.04:

Step 1: Install the required packages

Open a terminal and run the following command to install the required packages:

sudo apt update
sudo apt install postfix dovecot-imapd dovecot-pop3d

This will install the Postfix MTA, Dovecot IMAP and POP3 server, and other dependencies.

Step 2: Configure Postfix

Postfix is the MTA that will handle email delivery. Edit the Postfix configuration file using the following command:

sudo nano /etc/postfix/main.cf

Add the following lines to the end of the file:

mydestination = example.com
myhostname = mail.example.com
myorigin = $myhostname

Replace example.com with your domain name.

Step 3: Configure Dovecot

Dovecot is the MDA that will handle email retrieval. Edit the Dovecot configuration file using the following command:

sudo nano /etc/dovecot/dovecot.conf

Add the following lines to the end of the file:

mail_location = maildir:~/Maildir
first_valid_uid = 1000
first_valid_gid = 1000

Step 4: Configure the mail user

Create a new user and group for the mail server:

sudo useradd -m -s /bin/false mailuser
sudo groupadd mailgroup

Add the mail user to the mail group:

sudo usermod -aG mailgroup mailuser

Step 5: Set up the mail directory

Create the mail directory and set the correct permissions:

sudo mkdir -p /var/mail
sudo chown -R mailuser:mailgroup /var/mail

Step 6: Start and enable the services

Start the Postfix and Dovecot services:

sudo systemctl start postfix
sudo systemctl start dovecot

Enable the services to start automatically on boot:

sudo systemctl enable postfix
sudo systemctl enable dovecot

Step 7: Test the mail server

Use the telnet command to test the mail server:

telnet mail.example.com 25

This should connect you to the mail server. You can then send a test email using the mail command:

mail -s "Test email" [email protected]

Replace [email protected] with the email address you want to send the test email to.

Step 8: Configure the mail client

To access your email using a mail client, you'll need to configure it to use the mail server. The exact steps will depend on the mail client you're using. For example, if you're using Thunderbird, you can add a new account by going to File > Account Settings > Add Mail Account, and then entering the following settings:

Replace mail.example.com with your mail server's hostname, and your email address and your email password with your actual email address and password.

That's it! You should now have a basic mail server up and running on your Ubuntu 20.04 system.