Build SMTP server with iRedMail on Ubuntu 22.04 in Simple Steps

smtp-server-iredmail

Building an SMTP server with iRedMail could be a little tricky for beginners. But it’s still easy compared to building SMTP with Mailcow or Postal. If you are looking for the easiest way to build your own SMTP server then perhaps you should check building SMTP server with Mailinabox.

About iRedMail

iRedMail is an open-source mail server script with a very good number of developers contributing to its development on GitHub. It is free of cost but if you want an advanced admin panel to manage users then you have to pay for it, though the basic admin panel is free.

Features of iRedmail

iRedMail comes with inbuilt Webmail, Calendar, Contacts, ActiveSync, Antispam, Antivirus, greylisting, whitelisting, blacklisting, etc. It also supports MariaDB, PostgreSQL, and OpenLDAP backends. This means you have complete freedom to choose the database type.

Perhaps iRedMail is the only mail server solution that can be installed on all versions of Linux. So, here also you have the flexibility to deploy iRedMail on your favorite Linux distribution.

Requirement

Like every mail server, you will need

  • a domain from Namecheap
  • A VPS or Cloud with a minimum of 2 GB RAM

I will be using Contabo for demonstration but you are free to make your choices. I already have demonstrated the steps to get a domain name and VPS in the following video.

Updating DNS records

First thing first make changes to DNS records. Login to your domain registrar and create A record for mail.inlearn.in.

After that create or update the MX record pointing to mail.inlearn.in with priority 10.

Then create a TXT record for SPF entry and all following in value

v=spf1 mx ~all

Initial Setup

First of all, we need a way to connect to the server. Though it’s simple on Linux or MacOS, for Windows you will need an SSH client like Putty or Bitvise. Download it and connect it to your server

Switch to the root user

sudo -i

Set the hostname with the following command on Ubuntu

hostnamectl set-hostname mail

Don’t forget to replace inlearn.in with your domain name.

Then open hosts with the following command

apt install nano -y
nano /etc/hosts

Now add the following lines and don’t forget to replace the domain name and IP

45.354.212.212 mail.inlearn.in mail
127.0.1.1 mail.inlearn.in mail
127.0.0.1 mail.inlearn.in mail localhost localhost.localdomain

After that add a short hostname

nano /etc/hostname

Just make sure your short hostname is present in the file. If not just add it and reboot.

mail

Let’s update the OS.

apt update -y
apt upgrade -y

We need to install dialog package, which is in the universe repository. To enable that, use the following command.

sudo add-apt-repository universe
sudo apt update

Next, install gzip package

apt install -y gzip dialog

Our initial setup is complete now.

Installing iRedMail

Here the first step would be to get the iRedMail. Go to the iRedMail website and download the installer.

download-iredmail

Now connect to your server with any FTP client, let’s say WinSCP or FileZilla, and upload the iRedMail installer. Or, alternatively, download with the following command

wget https://github.com/iredmail/iRedMail/archive/refs/tags/1.6.8.tar.gz

Next, extract it and begin the installation with the following command

tar zxvf 1.6.8.tar.gz
cd iRedMail-1.6.8
bash iRedMail.sh

Answer the series of questions appearing on your screen to finalize the iRedMail installation.

Select email directory location

iredmail-select-email-directory-location

Select webserver type, if you don’t want to run any applications on this server you can skip it.

select-webserver

Select database type. If you want to run mail only server use OpenLDAP but if you are planning to host application as well then select MariaDB or PostgreSQL.

The following screen pops up only if you select OpenLDAP.

Specify LDAP suffix

Now type the MySQL administrator password

Finally, enter the domain name here

enter-the-domain-name

Now you will be asked to enter postmaster password

Here on this final screen, you have the option to install Webmail, Calendar, Address book & Activesync. Do not select SOGo unless your system has at least 8 GB of RAM. Make your selection then hit next.

Finally the summary of all your choices. If you want to make any modifications press CTRL+C to stop the installation and start once again. Otherwise, type Y and continue.

At the end of installation, you will be asked to change the SSH port (port 22) or continue

Now the installation has been finished. Reboot the system to enable all mail services.

Also, copy the different URLs generated for your application.

To open webmail go to https://mail.inlearn.in/mail

To open the admin panel go to https://mail.inlearn.in/iredadmin

Login with your username and password

Now here you can add domains, create users, etc.

Copying DKIM record to the DNS

To get the DKIM record go to the terminal and run the following command.

amavisd-new showkeys

The output would be something like this

dkim._domainkey.mydomain.com.   3600 TXT (
  "v=DKIM1; p="
  "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYArsr2BKbdhv9efugByf7LhaK"
  "txFUt0ec5+1dWmcDv0WH0qZLFK711sibNN5LutvnaiuH+w3Kr8Ylbw8gq2j0UBok"
  "FcMycUvOBd7nsYn/TUrOua3Nns+qKSJBy88IWSh2zHaGbjRYujyWSTjlPELJ0H+5"
  "EV711qseo/omquskkwIDAQAB")

Copy the output of the command inside ( ) in one line and remove all quotes.

 v=DKIM1; p= MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYArsr2...................

After these steps secure your iRedMail server to deal with SSL warnings.

Conclusion

Installing iRedMail is easy and quick. It is loaded with several features and you have options to make a selection of features you like to install. It is a very robust system and it can easily handle a good amount of traffic.

8 replies
  1. sunil singh
    sunil singh says:

    Thank you for explaining each steps in so much detail

    i have been following your video for setting up smtp server from scratch on ubuntu server ,
    i followed mailcow, iredmail and postal …..all three cases i was able to install them successfully and login into their dashboard

    however the issue i am facing for all of them is not able to send email to any email IDs ….facing same issue with postal , iredmail and mailcow as well

    i using google cloud VM to setup the SMTP server

    Thank you,
    Sunil

    Reply
      • Mr X
        Mr X says:

        I have tried it too, did not work. Got an error that v 1.4.2.tar.gz is outdated, went on to try the latest version. It still did not work.

        Can you test with v 1.5.1.tar.gz see if you can get it to work?

        I have tried 3 services providers all same.

        Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *