iRedMail is a script that installs and configures all the services needed to run a full-featured mail server.

  • Postfix SMTP server.
  • Dovecot IMAP server.
  • Nginx web server (admin panel and webmail).
  • OpenLDAP, MySQL/MariaDB, or PostgreSQL.
  • Amavisd-new (DKIM).
  • SpamAssassin (anti-spam).
  • ClamAV (anti-virus).
  • Roundcube (webmail).
  • SOGo (webmail, calendar, contacts, ActiveSync…).
  • Fail2ban (security).
  • mlmmj (mailing list).
  • Netdata (monitoring).
  • iRedAPD Postfix (greylisting).

Set the domain name:

sudo apt update && sudo apt upgrade -y
sudo hostnamectl set-hostname mail.example.com
sudo nano /etc/hosts

    127.0.0.1 mail.example.com mail localhost

Download using one of the following methods:

git clone https://github.com/iredmail/iRedMail/
cd iRedMail
chmod +x iRedMail.sh
sudo bash iRedMail.sh

    OR

wget https://github.com/iredmail/iRedMail/archive/1.4.0.tar.gz
tar xvf 1.4.0.tar.gz
cd iRedMail-1.4.0/
chmod +x iRedMail.sh
sudo bash iRedMail.sh

Get the latest version at [Link].

Follow the on-screen steps:

Your mail server is now up and running. As a best practice, set up an SSL/TLS certificate for the web server:

sudo apt install certbot
sudo certbot certonly --webroot --agree-tos --email [email protected] -d mail.example.com -w /var/www/html/
sudo nano /etc/nginx/templates/ssl.tmpl

Update the following lines in the Nginx config:

ssl_certificate /etc/letsencrypt/live/mail.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mail.example.com/privkey.pem;

Test and reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

Now configure the certificate for Postfix (SMTP) and Dovecot (IMAP):

sudo nano /etc/postfix/main.cf

Update the following lines:

smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/cert.pem
smtpd_tls_CAfile = /etc/letsencrypt/live/mail.example.com/chain.pem

Do the same for Dovecot:

sudo nano /etc/dovecot/dovecot.conf

Update the following lines:

ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem

Reload both services:

sudo systemctl reload postfix
sudo systemctl reload dovecot