Community Blog How to Set up iRedMail Server on a Linux ECS Server

How to Set up iRedMail Server on a Linux ECS Server

This tutorial shows you how to simplify the process of building an email server on Alibaba Cloud ECS with iRedMail.

By Alex Mungai Muchiri, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud's incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Having your own email server is very attractive for a number of reasons. To begin with, your internal mail server is pretty easy to manage in a variety of ways such as setting the storage capacity of your mails. It is also very convenient when doing backups, defining attachments requirements, managing logs and attaching as many domains as possible. However, getting your own email server working is a very complicated process that has until recently been only accessible to large organizations. The aim of this tutorial is to explore how the process can be simplified through the use of iRedMail.

Working with the iRedMail install script will enable you to set up your own mail server in about 20 minutes. We shall not be looking at how to set up a Linux server since your Alibaba Cloud ECS already comes preinstalled with an operating system.

An Overview of iRedMail

The iRedMail includes a shell script that will get the components necessary for your email server running in your ECS instance. The process is rather simple and automatic and eliminates nearly all manual processes for setting up a mail server. It supports common operating systems such as CentOS, Ubuntu, and OpenBSD. The most notable features in the iRedMail are as follows:

  • It is constituted of open source packages mostly.
  • It incorporates a secure transport layer as a default and supports HTTPS webmail as well as SMTP/IMAP.
  • It allows you to create virtually unlimited mailboxes using a simple-to-use panel.
  • You have plenty of option for mail storage including PostgreSQL, OpenLDAP as well as MySQL

The following are the major components used in iRedMail and all of them are open source:


  • Postfix SMTP server
  • Dovecot IMAP
  • Apache
  • Nginx
  • iRedAPD Postfix policy server


  • OpenLDAP, ldapd
  • MySQL/MariaDB, PostgreSQL


  • Amavised-new
  • SpamAssassin
  • ClamAV
  • Roundcube webmail
  • SOGo Groupware
  • Fail2ban
  • Awstats

Requirements for Installation

The first consideration is the specifications for your ECS instance. You should have at least 2GB of RAM on your server as the installed components take up to a GB of your RAM. Another thing to consider is if there are other components installed: it is recommended that you have a separate VPS for your websites and blogs lest you risk breaking your installations. With that in check, let us now get to the actual process of installing iRedMail:

Step 1: Ensure your IP address is not listed in the blacklist sites by checking from mxtoolbox.com and dnsbl.info. If it is, you may have to use a different instance (but it is unlikely a fresh Alibaba Cloud ECS would be blacklisted).

Step 2: you should update your ECS instance so that all the installed software is the most recent and capable of running your mail server. SSH into your server and run the command below to update:

sudo apt update
sudo apt upgrade

Great, we have successfully completed the first steps at this point.

Now, in the next steps, we shall install iRedMail, which comes with the packages that we listed above. The process will install utilities such as Apache, MySQL or PostgreSQL among others such as Postfix, Dovecot, and iptables. It is the reason why we recommended that you make the installation in a clean ECS instance. Now follow the steps below:

The Installation Process

FQDN Setup

FQDN stands for fully qualified domain name, and this step involves the setting up of a hostname to run on our ECS instance. This step is very crucial as it will be the cornerstone of your emailing service. Run the command indicated below to see the current hostname:

hostname -f

You should see the hostname in the location below:

sudo nano /etc/hostname

The command below will set the fully qualified domain name (FQDN) of your server:

sudo hostnamectl set-hostname mail.example.com

To update the /etc/hosts file, navigate to the path below and list the FQDN hostname as the first item on the list:

sudo nano /etc/hosts

Your listed FQDN item listed in the location above should be as below       mail.example.com localhost

Replace the URL above with your own and ensure that you have used the address of the local host just as is seen above.

Now, you should run the command below to ascertain that the intended changes have taken effect:

hostname -f

Sometimes you may be forced to reboot the VPS for the changes to take effect. If even after the reboot the changes are still unavailable, repeat the process of FQDN setup illustrated above. If all looks good, let us now proceed to the next step of this process.

MX Record

MX records are particularly important in email forwarding since they help resolve email hosts. For instance, example.com's email host can be mail.example.com. When sending an email to example.com's server, its MX record will first be queried to figure out the emails host for that server. The A record will the be queried to resolve the target IP address so that the email can be sent .

In this step, we shall set both the MX and A records of our domain. Usually, an MX record points to the FQDN of the mail server. See details below:

Record Type    Name      Value

MX             @         mail.example.com

Next is the A record

Record Type    Name     Value

A              mail     Server-IP

For IPv6 addresses, ensure that the AAAA record is also added.

Great, let us now proceed to the next step

SELinux Configuration

Now, in this step, we shall disable SELinux so that iRedMail can successfully run in our VPS. It is noteworthy that the two are incompatible and our mail server will not work until the SELinux is disabled.

You will need to access the SELinux configuration in the /etc/selinux/config file. In the file, you should set its value as 'disabled' as indicated in the below:

sudo nano /etc/selinux/config

Great, we have successfully completed this step. Let us now proceed to the next step, which is to download iRedMail.

iRedMail Download

In this step, we shall download iRedMail to our VPS from the official download page. As a rule, always work with the most stable version rather than the most recent. Once that is done, unpack the files in a folder in readiness for the installation process:

The command below will download the iRedMail files to your server:

wget https://github.com/iredmail/iRedMail/releases/download/1.0/iRedMail-1.0.tar.gz

Once that is complete, run the extraction command below:

tar xjf iRedMail-0.9.8.tar.bz2

Remove the downloaded file like so:

sudo rm -r iRedMail-0.9.8.tar.bz2

Now, we are all set for the final installation of iRedMail after the iRedMail tarball has been extracted to your VPS.

iRedMail Installation

We already have all the necessary components for the installation process. We shall not dwell so much on the questions that you shall be required to answer during this process because they are all straight-forward. Run the command below for this next step:

cd iRedMail-0.9.8
bash iRedMail.sh

Follow the prompts to start the installation process. All packages will be automatically installed and configured for your mail server. Once the run is complete, you have successfully installed iRedMail in your VPS.

Steps to Follow

After you run the commands above, you will be prompted to press Enter to accept the installation. You will also be required to set the path for mailbox storage or simply leave the default at /var/vmail.

Select your preferred web server or leave Nginx as the default.

Next, choose the database that will store email accounts from the options provided, I chose MariaDB but you can make a different choice.

Next, create a password for the database root user on localhost.

Next, create an email account and set the password or simply create a password for the default postmaster@domain.com account.

Next, choose additional plugins to add extra features as you may find useful, review your choices and press Enter to install.

Authorise iRedMail firewall rules and then restart the firewall by running the commands below:

sudo ufw enable
sudo ufw reload

Finally, restart your server by running the command below:

systemctl reboot

The admin panel should now be accessible at https://mx.example.com/iredadmin/

For more information about your server, open the tips files like so:

sudo nano /root/iRedMail-0.9.8/iRedMail.tips

Finally, note that this tutorial is for demonstration purposes and the MX and A records used are not valid. We have also used a fictional DNS name. A setup that will send emails and receive them requires the use of real configurations for use by Postfix.

Advantages of Using iRedMail

If you opt to use iRedMail, you will enjoy a number of features that you will find useful. Some of the most notable of these are as discussed below:

  • There are no setup costs, save for the ECS costs, for a fully fledged and featured mail server, that is, unless you want the enterprise edition.
  • iRedMail is compatible most Linux distributions making it very accessible. You can deploy it in Ubuntu, Red Hat, CentOS, Debian, Free BSD as well as Open BSD.
  • It comes pre-packaged with calendar (CalDAV) and contact (CardDAV) services out of the box.
  • It is both easy to deploy, unsophisticated and does not need specialized maintenance.
  • You can create virtually unlimited mail accounts on your server.
  • You can choose your backend from up to four different options (OpenLDAP, MySQL, MariaDB, and PostgreSQL).
  • Integrated features for mail restrictions
  • Integrates a feature for the sender and receiver throttling
  • Integrates security features such as anti-spam ware and anti-malware.
  • Comes pre-packaged with Webmail's mail management tools such as AJAX, vacations, filters and address books.
  • You can easily port or save a copy of your deployed instance in a reproducible server setup.
  • Having your own mail server is very advantageous for privacy since all data is within your control.
  • iRedMail uses open source components that are both free to use and updated regularly. The vendors run routine fixes and upgrades and are independent of the iRedMail project.
  • Finally, it is compatible with both virtualized environments such as KVM, HV, VMware or non-virtualized environments and for both 32-bit and 64-bit distributions.


Congratulations for making it this far, you have successfully deployed your mail server. Access the iRedAdmin via https://example.com/iredadmin and then login using the credentials you created during the installation process If you want to test if the configurations work properly, you may want to use services such as Mail Tester. Mail Tester is used by many developers to check what aspects of their configurations need some improvements.

Don't have an Alibaba Cloud account? Sign up for an account and try over 40 products for free worth up to $1200. Get Started with Alibaba Cloud to learn more.

0 0 0
Share on


53 posts | 8 followers

You may also like


53 posts | 8 followers

Related Products