How to Set Up an iRedMail Mail Server on Ubuntu EC2 with Multiple Domain Management
In today’s world, managing a dedicated mail server for your domain or business is essential for security, privacy, and control over your communications. iRedMail is an open-source mail server solution that simplifies the setup and management of a full-featured email server, including support for multiple domains.
This guide walks you through the entire process—from launching an EC2 instance on AWS, setting up iRedMail on Ubuntu, configuring DNS records, and managing multiple domains and email accounts.
Prerequisites
- An Ubuntu EC2 instance (preferably Ubuntu 20.04 or later)
- Elastic IP for your EC2 instance
- A domain name (e.g.,
example.com
)
Step 1: Prepare Your EC2 Instance
- Launch an Ubuntu EC2 Instance
- In the AWS EC2 dashboard, launch a new instance using Ubuntu 20.04 LTS. Ensure that the security group allows the following ports:
- 25 (SMTP)
- 587 (SMTP Submission)
- 993 (IMAP)
- 443 (HTTPS)
- Update Your Server
- After SSHing into your EC2 instance, update it with:
sudo apt update && sudo apt upgrade -y
- Set the Hostname
- Set a fully qualified domain name (FQDN):
sudo hostnamectl set-hostname mail.example.com
Step 2: Install iRedMail
- Download the iRedMail Installer
- Navigate to
/tmp
and download the iRedMail installer:
cd /tmp wget https://github.com/iredmail/iRedMail/archive/refs/tags/1.7.1.tar.gz -O iRedMail.tar.gz
- Extract and Run the Installer
- Extract the installer and run it:
tar xvf iRedMail.tar.gz cd iRedMail-1.7.1/ sudo bash iRedMail.sh
- Follow Installation Prompts
- The installer will prompt you to:
- Select the mail directory (
/var/vmail
by default) - Choose Nginx or Apache as the web server (Nginx is recommended)
- Set up MySQL/MariaDB as the database backend
- Provide your domain name (e.g.,
example.com
) - Set up an admin email (e.g.,
postmaster@example.com
)
After the installation, reboot your system:
sudo reboot
Step 3: Access the iRedAdmin Panel
- Log in to the Admin Panel
- Once the system reboots, access iRedAdmin at:
https://mail.example.com/iredadmin
- Log in with the admin email (e.g.,
postmaster@example.com
). - Add a New Domain
- In the iRedAdmin panel, navigate to Domains and Accounts → Add Domain. Enter your new domain name (e.g.,
newdomain.com
) and set up email accounts.
Step 4: Configure DNS Settings
To ensure email delivery, configure the DNS records for your domain.
- MX Record
- Type:
MX
- Host:
@
- Priority:
10
- Mail Server:
mail.example.com
- A Record
- Type:
A
- Host:
mail
- Value:
<Your Elastic IP>
- SPF Record
- Type:
TXT
- Host:
@
- Value:
v=spf1 mx -all
Step 5: Add a New Domain to iRedMail
- Log in to iRedAdmin
- Access
https://mail.example.com/iredadmin
and log in with admin credentials.
- Add the New Domain
- Navigate to Domains and Accounts → Add Domain, and enter the new domain (e.g.,
newdomain.com
). - Configure DNS for the New Domain
- MX Record: Add a new MX record for the new domain, pointing to
mail.example.com
. - SPF Record: Set
v=spf1 mx -all
for the new domain.
Step 6: Secure the Server with Let's Encrypt SSL
- Install Certbot:
sudo apt install certbot
- Obtain an SSL Certificate:
sudo certbot certonly --nginx -d mail.example.com
- Configure Nginx to use the SSL certificate and restart Nginx:
sudo systemctl restart nginx