How to Set Up a Mail Server Using iRedMail on Ubuntu 16.04

Introduction

If you have ever built a mail server from the ground up, you know that it can be a tedious venture. There is another option for those of us who don’t want to spend time editing countless configuration files. iRedMail is an amazing shell script that automatically installs and configures all the components necessary for a fully functional mail server. iRedMail uses a complete package of open-source software, including:

In this tutorial, we will walk through all of the steps to get your mail server running and get it secured with SSL using Let’s Encrypt.

Prerequisites

Installation With iRedMail

Before getting started with the installation, you should update your system.

sudo apt-get update
sudo apt-get upgrade

Next, we will want to set our fully qualified domain name (FQDN) hostname. On Ubuntu, the hostname is set in 2 files, /etc/hostname and /etc/hosts.

Open /etc/hostname.

sudo nano /etc/hostname

Add your short hostname to the file, not your FQDN. If your full domain is mail.example.com your file should look like this.

mail

Next, open /etc/hosts and add your FQDN.

127.0.0.1   mail.example.com mail localhost localhost.localdomain

Reboot your server.

sudo shutdown -r now

You can now verify your hostname.

hostname -f

Now that your FQDN has been set, we can move on to the installation. Download the latest version of iRedMail using wget. You can find the latest build by visiting the iRedMail download page.

tar xvf iRedMail-0.9.7.tar.bz2
cd iRedMail-0.9.7

Next, extract the tarball and then cd to the directory.

tar xvf iRedMail-0.9.7.tar.bz2 cd iRedMail-0.9.7

Then, add permission to the script and run it with sudo.

chmod +x iRedMail.sh
sudo bash iRedMail.sh

You will see a setup wizard that will ask you some questions:

Now that everything has been entered, we just need to review the settings and begin the installation. After installation, you will be asked if you would like to use the firewall rules provided by iRedMail. The rule will be copied to /etc/default/iptables. To use this option, enter “y” and continue. You will then be shown some vital data, including:

This data can also be found at /home/yourusername/iRedMail-0.9.7/iRedMail.tips.

Reboot your server.

sudo shutdown -r now

After rebooting, you can access the web admin page at https://mail.example.com/iredadmin using your domain. To access your email, use the Roundcube page at https://mail.example.com/mail. iRedMail installs the server with a self-signed certificate, which requires special permissions to open the page in your browser. It is recommended that you upgrade to an official CA certificate. Let’s Encrypt is a CA that offers free certificates. Visit Setup Let's Encrypt on Linux for information on using this service. Once the certificate is obtained, you will need to replace the self-signed certs.

sudo cp /path/to/your/cert /etc/ssl/certs/iRedMail.crt
sudo cp /path/to/your/key /etc/ssl/private/iRedMail.key

Restart all services using the key. If you’ve used Nginx for your web server, you would replace apache2 with nginx.

sudo systemctl restart postfix
sudo systemctl restart apache2
sudo systemctl restart dovecot