Introduction
Running your own mail server offers the benefit of privacy as well as the ability to create as many mail accounts as you wish for your domains.
This tutorial will show you how to install iRedMail, an open source mail server setup script, on a fresh installation of Ubuntu 18.04. iRedMail saves you time by installing and setting up all of the components you need to run an email server, such as:
- Postfix - A mail transfer agent (MTA)
- Dovecot - An IMAP and POP3 server
- Nginx - A web server
- OpenLDAP - LDAP server for storing mail accounts or a MySQL, MariaDB or PostgreSQL server for storing mail accounts.
- SpamAssassin - A spam scanner
- ClamAV - A virus scanner
- Amavisd - An interface between Postfix, SpamAssassin and ClamAV
- iRedAPD - Postfix policy server
Optional:
- Roundcube - A webmail interface
- SOGo Groupware - A calendar, contact and tasks service
- Fail2ban - Restricts and bans logins from IP addresses that look malicious
Requirements
- A fresh Ubuntu 18.04 Rcs Cloud Compute instance with at least 2GB of memory (4GB is preferred) for a low traffic mail server
- Port 25 unblocked
- A non-blocked IP address. If your IP address has been added to a block list, your emails will be marked as spam and may never reach their destination. You can check whether your IP address is on a block list by entering it here.
- A non-root sudo user
- Verify the server's outbound port status.
Installation
First, you will want to set your fully qualified domain name (FQDN) hostname. Enter hostname -f
to view the current hostname.
hostname -f
On Ubuntu, the hostname is set in two files: /etc/hostname
and /etc/hosts
. Open /etc/hostname
.
sudo nano /etc/hostname
In /etc/hostname
, the short form of the hostname is given, not the FQDN hostname. Enter the short form of the hostname you wish to use. For example, if the FQDN hostname you wish to use is mail.example.com
, your file will look like the following.
mail
Next, open /etc/hosts
.
sudo nano /etc/hosts
Add your FQDN hostname as the first item.
127.0.0.1 mail.example.com mail localhost localhost.localdomain
Close the file and reboot your server.
sudo shutdown -r now
Once your server is up and running again, you can verify your hostname.
hostname -f
Install the bzip2
package so that you can uncompress the downloaded iRedMail package.
sudo apt-get install bzip2
You are now ready to install iRedMail. Download the latest version of iRedMail using wget. You can find the latest build by visiting the iRedMail download page.
wget https://bitbucket.org/zhb/iredmail/downloads/iRedMail-0.9.9.tar.bz2
Extract the tarball and then cd
to the directory.
tar xvf iRedMail-0.9.9.tar.bz2
cd iRedMail-0.9.9
Then, add the appropriate permissions for the iRedMail installer script and run it with sudo
.
chmod +x iRedMail.sh
sudo bash iRedMail.sh
The iRedMail installer script will ask you a series of questions before setting up the mail server for you. Choosing the default options is recommended if you are new to running a mail server.
Running the script will open a Welcome screen. Select Yes
to continue.
The next screen will allow you to set the default mail storage path, which is /var/vmail
. Select Next
to continue.
The next screen allows you to choose your preferred back-end to store mail accounts. Make your selection and then select Next
to continue.
You will then be asked to enter your first mail domain name. This will be your domain from earlier without the sub-domain. For example if your FQDN is mail.example.com
then you would enter example.com
as your first mail domain name. Enter your domain name and then select Next
to continue.
An administrator account for your first mail domain. This account is both an admin account and a mail user, therefore you can login to webmail and the admin panel (iRedAdmin) with the same credentials. The username is the full email address. You will be asked to set the password for the admin account.
Once you have entered a suitably strong password, select Next
to continue.
You will then be asked to choose optional components that can be installed, such as SOGo. At a minimum, you should choose iRedAdmin
and Roundcube
.
Once you have selected the optional components you want to be installed, select Next
to continue.
The iRedMail installer will ask you to review and confirm your iRedMail configuration before the installation proceeds. Type y
and press Enter to start the installation.
Once the installation is complete, you will be asked whether you would like to use the firewall rules provided by iRedMail and whether you want to restart the firewall now. Type y
or Y
and press Enter to use the default firewall rules and to restart the firewall.
After all the required packages are installed and configured, 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 mail, use the Roundcube page at https://mail.example.com/mail
. The server is installed with a self-signed certificate which requires special permissions to open the page in your browser. It is recommended that you upgrade to a certificate from a Certificate Authority (CA). Let's Encrypt is a CA that offers free certificates. Read the Rcs Setup LetsEncrypt on Linux article for information about using this service. You will need to follow the instructions for Nginx
, as it is the default web server that iRedMail installs. Once the certificate is obtained you will need to replace the self-signed certificates that iRedMail creates.
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 that require the SSL certificate key.
sudo systemctl restart postfix
sudo systemctl restart nginx
sudo systemctl restart dovecot
Enjoy your new mail server! Be sure to read the iRedMail.tips
file which is in the iRedMail-0.9.9
directory created within the directory you uploaded iRedMail to. The file contains:
- The URLs, usernames and passwords of the web-based applications installed by iRedMail
- The location of mail service related software configuration files
- Additional important and sensitive information
You will also need to set the DNS records for your mail server before you can send and receive mail. Read the Introduction to Rcs DNS tutorial for information about setting DNS records.