Mail server on ubuntu

Setting up a mail server on Ubuntu! Here's a step-by-step guide to help you get started:

Prerequisites

  1. Ubuntu 20.04 or later (other versions may work, but this guide is specifically for 20.04)
  2. A domain name (e.g., example.com)
  3. A static IP address or a dynamic DNS (DDNS) service
  4. A mail client (e.g., Thunderbird, Outlook) to test your setup

Step 1: Install Postfix

Postfix is a popular open-source mail transfer agent (MTA) that will handle email delivery. Run the following command:

sudo apt-get update
sudo apt-get install postfix

Step 2: Configure Postfix

Edit the Postfix configuration file:

sudo nano /etc/postfix/main.cf

Add the following lines at the end of the file:

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

Replace example.com with your domain name.

Step 3: Set up DNS

Create a TXT record in your DNS provider's control panel:

@ IN TXT "v=spf1 a mx ptr include:example.com -all"

This sets up a Sender Policy Framework (SPF) record to prevent spam.

Step 4: Set up Mailbox

Create a mailbox for the root user:

sudo useradd -m -s /bin/false root
sudo passwd root

Step 5: Configure Mail Client

In your mail client, set up a new account using the following settings:

Step 6: Test Your Setup

Send an email from your mail client to an external address (e.g., Gmail). If everything is set up correctly, you should receive the email.

Additional Tips

That's it! You now have a basic mail server set up on Ubuntu.