How to Easily Set Up a Full-Featured Mail Server on Ubuntu 18.04 with iRedMail

Setting up your own email server on Linux from scratch is a pain in the butt, if you are not an advanced user. This tutorial will be showing you how to use iRedMail to quickly set up a full-featured mail server on Ubuntu 18.04, saving you lots of time and headaches.

What is iRedMail?

iRedMail is a shell script that automatically install and configure all necessary mail server components on your Linux/BSD server, thus eliminating manual installation and configuration. With iRedMail, you can easily create unlimited mailboxes and unlimited mail domains in a web-based admin panel. Mailboxes can be stored in MariaDB/MySQL, PostreSQL database or OpenLDAP. Open-source software used in iRedMail are as follows:

  • Postfix SMTP server
  • Dovecot IMAP server
  • Nginx web server
  • OpenLDAP, ldapd
  • MySQL/MariaDB, PostgreSQL
  • Amavised-new
  • SpamAssassin
  • ClamAV
  • Roundcube webmail
  • SOGo Groupware
  • Fail2ban
  • mlmmj mailing list manager
  • Netdata server monitoring
  • iRedAPD Postfix policy server for greylisting

Step 1: Choose the Right Hosting Provider and Buy a Domain Name

To set up a complete email server with Modoboa, you need a server with at least 2GB RAM, because after the installation, your server will use more than 1GB of RAM. This tutorial is done on a $10/month Vultr VPS (virtual private server). I recommend Vultr because it allows you to send emails via port 25, so you can send unlimited emails (transactional email and newsletters) without spending money on SMTP relay.

Other VPS providers like DigitalOcean blocks port 25. DigitalOcean would not unblock port 25, so you will need to set up SMTP relay to bypass blocking, which can cost you additional money.

Create an account at Vultr, then create a server instance in the Vultr web control panel and install Ubuntu 18.04 on it. There are 4 types of server in Vultr. Here we will choose the $10/month plan in Cloud Compute, which costs less than the other 3 types and is good enough to run Modoboa.

vultr mail server

It is recommended that you follow the instructions below on a clean install of Ubuntu 18.04 system. Installing a piece of complex server software like Modoboa on a non-LTS Ubuntu is discouraged as you will probably encounter problems when upgrading your OS every 9 months. The software author doesn’t have time to support every Ubuntu release. It is far better for your mail server to stay stable for 2 or 5 years.

You also need a domain name. I registered my domain name from NameCheap because the price is low and they give whois privacy protection free for life.

Also, make sure your server IP address isn’t listed in any email blacklist. You can go to mxtoolbox.com and dnsbl.info to check your server IP address. If it’s in a blacklist, you can delete your server instance in Vultr and create a new one. As Vultr uses an hourly billing model, you won’t be charged by month, but by how many hours you used, which makes it convenient to delete a server instance at any time.

Step 2: Creating DNS MX Record

The MX record specifies which host or hosts handle emails for a particular domain name. For example, the host that handles emails for linuxbabe.com is mail.linuxbabe.com. If someone with a Gmail account sends an email to [email protected], then Gmail server will query the MX record of linuxbabe.com. When it finds out that mail.linuxbabe.com is responsible for accepting email, it then query the A record of mail.linuxbabe.com to get the IP address, thus the email can be delivered.

In your DNS manager, create a MX record for your domain name. Enter @ in the Name field to represent the main domain name, then enter mail.your-domain.com in the Value field.

modoboa web interface

Note: The hostname for MX record can not be an alias to another name. Also, It’s highly recommended that you use hostnames, rather than bare IP addresses for MX record.

Your DNS manager may require you to enter a preference value (aka priority value). It can be any number between 0 and 65,356. A small number has higher priority than a big number. You can enter 0 for your email server, or accept the default value. After creating MX record, you also need to create an A record for mail.your-domain.com , so that it can be resolved to an IP address. If your server uses IPv6 address, be sure to add AAAA record.

Hint: If you use Cloudflare DNS service, you should not enable the CDN feature when creating A record for your mail server. Cloudflare does not support SMTP proxy.

Step 3: Configuring Hostname

Log into your server via SSH, then run the following command to update existing software packages.

sudo apt update

sudo apt upgrade

And set a fully qualified domain name (FQDN) for your server with the following command.

sudo hostnamectl set-hostname mail.your-domain.com

We also need to update /etc/hosts file.

sudo nano /etc/hosts

Edit it like below:

127.0.0.1       mail.your-domain.com localhost

Save and close the file. To see the changes, re-login and then run the following command to see your hostname.

hostname -f

Step 4: Setting up Mail Server on Ubuntu 18.04 with iRedMail

Run the following command download the iRedMail Bash installer with wget. At the time of this writing, the latest version of iRedMail is 0.9.8, released on April 3, 2018. Please go to iRedMail download page  to check out the latest version.

wget https://bitbucket.org/zhb/iredmail/downloads/iRedMail-0.9.8.tar.bz2

You can always use the above URL format to download the latest version. Just replace 0.9.8 with the new version number.

Extract the tarball.

tar xvf iRedMail-0.9.8.tar.bz2

Then cd into the newly created directory.

cd iRedMail-0.9.8/

Add executable permission to the iRedMail.sh script.

chmod +x iRedMail.sh

Next, run the Bash script with sudo privilege.

sudo bash iRedMail.sh

The ncurse-based setup wizard will appear. Select Yes and press Enter.

ubuntu 18.04 iredmail

The next screen will ask you to select the mail storage path. You can use the default one /var/vmail, so simply press Enter.

iredmail default storage path

Then choose whether you want to run a web server. It’s highly recommended that you choose to run a web server because you need the web-based admin penal to add email accounts. Also it allows you to access the Roundcube webmail. By default, Nginx web server is selected, so you can simply press Enter.  (An asterisk indicates the item is selected.)

iredmail nginx web server

Then select the storage backend. Choose one that you are familiar with. This tutorial chose MariaDB. Press up and down arrow key and press the space bar to select.

ubuntu 18.04 email server

If you selected MariaDB or MySQL, then you will need to set the MySQL root password.

ubuntu 18.04 mail server

Note that if you selected MariaDB, then you don’t need password to log into MariaDB shell. Instead of running the normal command mysql -u root -p, you can run the following command to login, with sudo and without providing MariaDB root password.

sudo mysql -u root

This is because the MariaDB package on Ubuntu 18.04 uses unix_socket authentication plugin, which allows users to use OS credentials to connect to MariaDB, but you still need to set root password in iRedMail setup wizard.

Next, enter your first mail domain. You can add additional mail domains later in the web-based admin panel. This tutorial assumes that you want an email account like [email protected], in that case, you need to enter your-domain.com here, without sub-domain. Do not press the space bar after your domain name. I think iRedMail will copy the space character along with your domain name, which can result in installation failure.

set up mail server on ubuntu 18.04

Next, set a password for the mail domain administrator.

ubuntu 18.04 email server step by step

Choose optional components. By default, 4 items are selected. If you like to have SOGo groupware, then select it and press Enter.

iredmail component

Now you can review your configurations. Type Y to begin the installation of all mail server components.

iredmail review

At the end of installation, choose y to use firewall rules provided by iRedMail and restart firewall.

iredmail firewall rules fail2ban

Now iRedMail installation is complete. You will be notified the URL of webmail, SOGo groupware and web admin panel and the login credentials. The iRedMail.tips file contains important information about your iRedMail server.

iredmail full featured mail server

Reboot your Ubuntu 18.04 server.

sudo shutdown -r now

Once your server is back online, you can visit the web admin panel.

https://mail.your-domain.com/iredadmin/

Because it’s using a self-signed TLS certificate, you need to add security exception.

Step 5: Installing Let’s Encrypt TLS Certificate

Since the mail server is using a self-signed TLS certificate, both desktop mail client users and webmail client users will see a warning. To fix this, we can obtain and install a free Let’s Encrypt TLS certificate.

Obtaining the Certificate

First, install Let’s Encrypt (certbot) client on Ubuntu 18.04

sudo apt install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt install certbot

iRedMail has already configured TLS settings in the default Nginx virtual host, so here I recommend using the webroot plugin, instead of nginx plugin, to obtain certificate. Run the following command. Replace red text with your actual data.

sudo certbot certonly --webroot --agree-tos --email your-email-address -d mail.your-domain.com -w /var/www/html/

When it asks you if you want to receive communications from EFF, you can choose No.

iredmail letsencrypt

If everything went well, you will see the following text indicating that you have successfully obtained a TLS certificate. Your certificate and chain have been saved at /etc/letsencrypt/live/mail.your-domain.com/ directory.

iredmail certbot

Note that sometimes, the self-signed certificate can prevent Let’s Encrypt ACME server from connecting to your server and the certificate won’t be issued. You can disable HTTPS on the default virtual host to fix this problem, then re-enable HTTPS after a valid Let’s Encrypt certificate is obtained.

Installing the Certificate in Nginx

After obtaining a TLS certificate, let’s configure Nginx web server to use it. Edit the SSL template file.

sudo nano /etc/nginx/templates/ssl.tmpl

Find the following 2 lines.

ssl_certificate /etc/ssl/certs/iRedMail.crt;
ssl_certificate_key /etc/ssl/private/iRedMail.key;

Replace them with:

ssl_certificate /etc/letsencrypt/live/mail.your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mail.your-domain.com/privkey.pem;

Save and close the file. Then test nginx configuration and reload.

sudo nginx -t

sudo systemctl reload nginx

Visit iRedMail admin panel again, your web browser won’t warn you any more because Nginx is now using a valid TLS certificate.

iredadmin

Installing TLS Certificate in Postfix and Dovecot

We also need to configure Postfix SMTP server and Dovecot IMAP server to use the Let’s Encrypt issued certificate so that desktop mail client won’t display security warning. Edit the main configuration file of Postfix.

sudo nano /etc/postfix/main.cf

Find the following 3 lines. (line 95, 96, 97).

smtpd_tls_key_file = /etc/ssl/private/iRedMail.key
smtpd_tls_cert_file = /etc/ssl/certs/iRedMail.crt
smtpd_tls_CAfile = /etc/ssl/certs/iRedMail.crt

Replace them with:

smtpd_tls_key_file = /etc/letsencrypt/live/mail.your-domain.com/privkey.pem
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.your-domain.com/cert.pem
smtpd_tls_CAfile = /etc/letsencrypt/live/mail.your-domain.com/chain.pem

Save and close the file. Then reload Postfix.

sudo systemctl reload postfix

Next, edit the main configuration file of Dovecot.

sudo nano /etc/dovecot/dovecot.conf

Fine the following 2 lines. (line 47, 48)

ssl_cert = </etc/ssl/certs/iRedMail.crt
ssl_key = </etc/ssl/private/iRedMail.key

Replace them with:

ssl_cert = </etc/letsencrypt/live/mail.your-domain.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.your-domain.com/privkey.pem

Save and close the file. Then reload dovecot.

sudo systemctl reload dovecot

From now on, desktop mail users won’t see security warnings.

Step 6: Sending Test Email

Log into iredadmin panel with the postmaster mail account. In the Add tab, you can add additional domains or email addresses.

add email addresses in iredadmin

If you see “no domain under control” error, please refer to this article.

After you create a user, you can visit the Roundcube webmail address and login with the new mail user account.

https://mail.your-domain.com/mail/

roundcube webmail

Now you can test email sending and receiving. Please note that you may need to wait a few minutes to receive emails because iRedMail by default enables greylisting, which is a way to tell other sending SMTP servers to try again in a few minutes. The following line in mail log file /var/log/mail.log indicates greylisting is enabled.

Recipient address rejected: Intentional policy rejection, please try again later;

Step 7: Unblocking Port 25 for Your Vultr Server

Your ISP or hosting provider won’t block incoming connection to port 25 of your server, which means you can receive emails from other mail servers.  However, many ISP/hosting providers block outgoing connection to port 25 of other mail servers, which means you can’t send emails.

If your email didn’t arrive at your other email address such as Gmail, then run the following command on your mail server to check if port 25 is blocked.

telnet gmail-smtp-in.l.google.com 25

If it’s not blocked, you would see messages like below, which indicates a connection is successfully established. (Hint: Type in quit and press Enter to close the connection.)

Trying 74.125.68.26...
Connected to gmail-smtp-in.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP y22si1641751pll.208 - gsmtp

If port 25 is blocked, you would see something like:

Trying 2607:f8b0:400e:c06::1a...
Trying 74.125.195.27...
telnet: Unable to connect to remote host: Connection timed out

If port 25 is blocked for outgoing connections on your Vultr server, then you should open a support ticket in your Vultr account. They will unblock port 25 for you. Here’s what I said to the support stuff.

Hi

I'm setting up a mail server. Looks like port 25 is blocked on this server. Please open it for me.

Thanks :)

The support stuff replied very quickly:

Hello XIAO GUOAN,

Thank you for your SMTP unblock request!

In order to combat spam and spam-like activities, we will need to review some additional information prior to removing the SMTP filter.

Please reply to this ticket with the following information:

1. The business name and organization URL(s) under which you offer services.
2. Describe, in as much detail as possible, the nature of the emails you intend to send.
3. The volume of email that you plan to deliver on a daily/monthly basis.

We need to know this in order to make an informed decision regarding your account settings and resource limits to ensure the integrity of our network/systems/online reputation.

Customer Support
www.Vultr.com

So you just need to answer 3 simple questions. You can use the following as a template. Note that if you are going to send newsletters, you need to tell that you will send newsletter and how your email list addresses are collected.

Hi

My business name is LinuxBabe and website is https://www.linuxbabe.com,

I'm setting up this mail server for my website, so I would be able to send registration emails and notification emails to my users.

The volume of outgoing email is below 100 emails per day.

Thanks.

And then the support stuff replied:

Hello,

Thank you for the information provided!

We have removed the default SMTP block on your account. Please restart any active instances via https://my.Vultr.com for the change to take effect (restarting via the server itself _will_not_ work).

Also, keep in mind that marketing and bulk email is restricted in our platform. For reference, our ANTI-SPAM policy is listed here: https://www.Vultr.com/legal/antispam_policy.php

If you have any additional questions our team is happy to assist you further. Thank you for choosing Vultr!

Kind Regards,
Customer Support

Once they removed the SMTP block on your account, you need to restart your server via the Vultr control panel for the change to take effect. Note that you can use Vultr server so send newsletters, as long as the recipients subscribed for it, but you are not allowed to send spam.

If your ISP or hosting provider (such as DigitalOcean) refuses to unblock port 25, then you can’t send emails directly, you also need to set up SMTP relay to solve this problem.

Step 8: Using Mail Clients on Your Computer or Mobile Device

Fire up your desktop email client such as Mozilla Thunderbird and add a mail account.

  • In the incoming server section, select IMAP protocol, enter mail.your-domain.com as the server name, choose port 993 and SSL/TLS. Choose normal password as the authentication method.
  • In the outgoing section, select SMTP protocol, enter mail.your-domain.com as the server name, choose port 587 and STARTTLS. Choose normal password as the authentication method.

iredmail-desktop-mail-client-configuration

Step 9: Improving Email Deliverablity

To prevent your emails from being flagged as spam, you should set PTR, SPF, DKIM and DMARC records.

PTR record

A pointer record, or PTR record, maps an IP address to a FQDN (fully qualified domain name). It’s the counterpart to the A record and is used for reverse DNS lookup, which can help with blocking spammers. Many SMTP servers reject emails if no PTR record is found for the sending server.

To check the PTR record for an IP address, run this command:

dig -x IP-address +short

or

host IP-address

Because you get IP address from your hosting provider or ISP, not from your domain registrar, so you must set PTR record for your IP in the control panel of your hosting provider, or ask your ISP.  Its value should be your mail server’s hostname: mail.your-domain.com. If your server uses IPv6 address, be sure to add a PTR record for your IPv6 address as well.

To edit the reverse DNS record for your Vultr server, log into Vultr control panel, select your server and the Settings tab. Then you can edit the reverse DNS record for both IPv4 and IPv6 address.

modoboa mail server PTR record

SPF Record

SPF (Sender Policy Framework) record specifies which hosts or IP address are allowed to send emails on behalf of a domain. You should allow only your own email server or your ISP’s server to send emails for your domain. In your DNS management interface, create a new TXT record like below.

modoboa spf record

Explanation:

  • TXT indicates this is a TXT record.
  • Enter @ in the name field to represent the main domain name.
  • v=spf1 indicates this is a SPF record and the version is SPF1.
  • mx means all hosts listed in the MX records are allowed to send emails for your domain and all other hosts are disallowed.
  • ~all indicates that emails from your domain should only come from hosts specified in the SPF record. Emails that are from other hosts will be flagged as forged.

To check if your SPF record is propagated to the public Internet, you can use the dig utility on your Linux machine like below:

dig your-domain.com txt

The txt option tells dig that we only want to query TXT records.

DKIM Record

DKIM (DomainKeys Identified Mail) uses a private key to digitally sign emails sent from your domain. Receiving SMTP servers verify the signature by using the public key, which is published in the DNS DKIM record.

The iRedMail script automatically configured DKIM for your server. The only thing left to do is creating DKIM record in DNS manager. Open the iRedMail.tips file under iRedMail-0.9.8 directory.

sudo nano iRedMail.tips

Scroll down to DNS record for DKIM support section. The DKIM public key is in the parentheses.

iredmail amavis dkim

You can also show the public key with the following command.

sudo amavisd-new showkeys

Then in your DNS manager, create a TXT record, enter dkim._domainkey in the name field. Copy everything in the parentheses and paste into the value field. Delete all double quotes.

amavisd-new ubuntu

After saving your changes, run the following command to test if your DKIM record is correct.

sudo amavisd-new testkeys

If the DKIM record is correct, the test will pass. Note that your DNS record may need sometime to propagate to the Internet.

TESTING#1 linuxbabe.com: dkim._domainkey.linuxbabe.com => pass

DMARC Record

DMARC stands for Domain-based Message Authentication, Reporting and Conformance. DMARC can help receiving email servers to identify legitimate emails and prevent your domain name from being used by email spoofing.

To create a DMARC record, go to your DNS manager and add a TXT record. In the name field, enter _dmarc. In the value field, enter the following:

v=DMARC1; p=none; pct=100; rua=mailto:[email protected]

create dmarc record txt

The above DMARC record is a safe starting point. To see the full explanation of DMARC, please check the following article.

Step 10: Testing Email Score and Placement

After creating PTR, SPF, DKIM record, go to https://www.mail-tester.com. You will see a unique email address. Send an email from your domain to this address and then check your score. As you can see, I got a perfect score. In the test result, you should check if your PTR record, SPF and DKIM record is valid.

imporve email server reputationMail-tester.com can only show you a sender score. There’s a another service called GlockApps that allow you to check if your email is landed in the recipient’s inbox or spam folder, or rejected outright. It supports many popular email providers like Gmail, Outlook, Hotmail, YahooMail, iCloud mail, etc

glockapps email placement test

What if Your Emails Are Still Being Marked as Spam?

I have more tips for you in this article: How to stop your emails being marked as spam. Although it will take some time and effort, your emails will eventually be placed in inbox after applying these tips.

Adding Multiple Mail Domains

I wrote this article to show you how to add multiple mail domains in iRedMail.

How to Disable Greylisting

By default, iRedMail has enabled greylisting, which tells other sending SMTP servers to try again in a few minutes. This is mainly useful to block spam, but it also degrades user experience. If you prefer to disable greylisting, follow the instructions below.

Add write permission to the /opt/iredapd/settings.py file.

sudo chmod 600 /opt/iredapd/settings.py

Then edit the configuration file.

sudo nano /opt/iredapd/settings.py

Find the following line.

plugins = ["reject_null_sender", "wblist_rdns", "reject_sender_login_mismatch", "greylisting", "throttle", "amavisd_wblist", "sql_alias_access_policy"]

Remove "greylisting" from the list. Save and close the file. Then restart iredapd.

sudo systemctl restart iredapd

Change the configuration file back to read only mode.

sudo chmod 400 /opt/iredapd/settings.py

Enabling SMTPS Port 465

If you are going to use Microsoft Outlook client, then you need to enable SMTPS port 465 in Postfix SMTP server.

How to Renew TLS Certificate

Let’s Encrypt issued TLS certificate is valid for 90 days only and it’s important that you set up a Cron job to automatically renew the certificate. You can run the following command to renew certificate.

sudo certbot renew

You can use the --dry-run option to test the renewal process, instead of doing a real renewal.

sudo certbot renew --dry-run

Error #1

If you see the following error when renewing TLS certificate:

The server could not connect to the client to verify the domain. Timeout during connect (likely firewall problem). Skipping.

This is mostly because you didn’t add AAAA record for mail.yourdomain.com, so create AAAA record in your DNS manager. You also need to enable IPv6 in Nginx virtual host. Edit the /etc/nginx/sites-enabled/000-default.conf file and find the following line.

#listen [::]:80;

Remove the # symbol to enable IPv6.

listen [::]:80;

Save and close the file. Then edit the SSL virtual host /etc/nginx/sites-enabled/00-default-ssl.conf. Add the following line.

listen [::]:443 ssl http2;

iredmail certbot renew

Save and close the file. Then test Nginx configuration.

sudo nginx -t

If the test is successful, reload Nginx for the change to take effect.

sudo systemctl reload nginx

Error #2

If you see the following error when renewing TLS certificate.

The client lacks sufficient authorization :: Invalid response

Then you need to create the hidden directory.

sudo mkdir -p /var/www/html/.well-known/acme-challenge

And set www-data as the owner of the webroot.

sudo chown www-data:www-data /var/www/html/ -R

Also, edit the SSL virtual host /etc/nginx/sites-enabled/00-default-ssl.conf. Add the following lines.

location ~ /.well-known/acme-challenge {
     root /var/www/html/;
     allow all;
}

iredmail letsencrypt renew

Save and close the file. Test Nginx configuration and reload.

sudo nginx -t
sudo systemctl reload nginx

Create Cron Job

If now the dry run is successful, you can create Cron job to automatically renew certificate. Simply open root user’s crontab file.

sudo crontab -e

Then add the following line at the bottom of the file.

@daily letsencrypt renew --quiet && systemctl reload postfix dovecot nginx

Reloading Postfix, Dovecot and Nginx is necessary to make these programs pick up the new certificate and private key.

Setting Up Backup Mail Server

Your primary mail server could be down sometimes. If you host your mail server in a data center, then the downtime is very minimal, so you shouldn’t be worried about losing inbound emails. If you host your mail server at home, the downtime can’t be predicted so it’s a good practice for you to run a backup mail server in a data center to prevent losing inbound emails. The backup mail server needs just 512MB RAM to run. Please check the full detail in the following article.

For Advanced Users

iRedMail doesn’t include a DMARC verification service, you can check out the following tutorial to set up OpenDMARC to block email spoofing.

You may want to customize the SpamAssassin content filter to better detect spam.

If your website and mail server are running on two different VPS (virtual private server), you can set up SMTP relay between your website and mail server, so that your website can send emails through your mail server. See the following article.

Wrapping Up

That’s it! I hope this tutorial helped you set up a mail server on Ubuntu 18.04 with iRedMail. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Rate this tutorial
[Total: 27 Average: 4.7]

166 Responses to “How to Easily Set Up a Full-Featured Mail Server on Ubuntu 18.04 with iRedMail

  • Will this work with Ubuntu Desktop?

    • To make it work on Ubuntu desktop in your home, you need to

      1). Have a static IP address, or set up dynamic DNS if your have a dynamic IP address.

      2). Configure port forwarding in your router. (SMTP port 25, IMAP port 993, submission port 587)

      3). If your ISP blocks port 25, then set up SMTP relay.

      It’s totally doable, if you are willing to get your hands dirty.

  • i can send mail but no mail is being received atm, i dont why ?

  • after disabled the “grey list” it works. thank you very much this tutorial. appreicate

  • Farax Abdi
    11 months ago

    Could we use another port (NOT 25) for sending email WITHOUT SMPT relay?

    • No. Receiving email servers expect you to hit them on port 25. They are listening on port 25 to accept incoming email.

      You can’t ask them to change the port. It’s SMTP standard. Similarly, you can’t ask websites to change port 80 to another port.

  • ihasaface
    11 months ago

    The first time i go to mail.mywebsite.com/iredadmin, I don’t get anything whatsoever… my website is up and running just fine though. Maybe because I have my webserver on a different VM than mail? please help.

    • To use iredadmin, you need to install a web server along with other components of iRedMail, preferably on the same VM. If you didn’t choose to run web server in the setup wizard, you can’t use iredadmin.

      • ihasaface
        11 months ago

        Is that going to mess with my website though? Changing hostname and hosts files and whatnot.

    • Changing hostname and hosts file won’t affect your website. The Nginx web server installed by iRedmail could interrupt your the operation of your website.

      And it’s a good idea to separate your website and email server on different boxes, because your email server can leak the origin IP address of your website if they are on the same box. To protect your website from DDoS attack, you probably want to use a CDN service, which will hide the IP address of your website.

      • Ihasaface
        11 months ago

        I’m confused…. I had my webserver on a different virtual box than my mail server…. But installing this on a separate box didn’t work. What am I missing?

    • Maybe you can just start it over.

  • How to create PTR, SPF, DKIM and DMARK records on Ubutu Desktop?

    • They are not created using command line. You need to ask your ISP or hosting provider to set the PTR record. For SPF, DKIM and DMARC records, create them in the DNS manager (on your domain registrar’s website).

  • Hi, I have two VPS servers with different IP addresses. On one of these servers I have my websites. Can I install iRedmail on second VPS and use it as mail server for domains from first server (with websites)?

  • Hey all,

    Was just trying this out on my AWS t2.micro EC2 instance. I got all the way up to the reboot just after the initial installation. I rebooted the machine and it is showing as running in the AWS EC2 console but I can’t SSH to it. I destroyed the instance, built a new one, and tried saying no to changing the firewall rules and I get the same result. Any ideas?

    • iRedMail uses the Linux iptables firewall, but you also need to make sure port 22 is opened at the AWS firewall.

      • Thanks for the reply. I configured the AWS firewall as you said. It ended up being the fact that the t2.micro instance in EC2 only has 1GB of RAM. That’s not enough to run the whole suite and you kind of end up DOSing yourself if you use it. The t2.medium has 2GB of RAM which is enough. My server is up and running well.

        For those that come after me and are doing this on AWS here’s a couple things to look out for:

        As Xiao Guo An said, make sure your iptables allow all the necessary ports. There’s a good table of ports that iRedMail needs open at this link https://docs.iredmail.org/network.ports.html

        Like I said, use a t2.medium or larger EC2 instance. t2.micro doesn’t provide enough resources.

        If you’re using Route53 for DNS, the syntax is a little bit different on there than it shows in the pictures. Pay attention to the syntax that Route53 likes.

        If you’ve attempted to use AWS SES in the past, be sure to remove any mention of it from your DNS records. They don’t play well together, especially when it comes to DKIM.

        • zydecci
          11 months ago

          When I said “make sure your iptables allow all the necessary ports” I really meant “make sure your security groups allow all the necessary groups.”

  • Steve Johnson
    11 months ago

    I understand why you need to setup mail.mydomain in /etc/hosts, but what is the purpose of changing the hostname itself? Because if there are multiple domains setup in the mailserver, you can only have one hostname.

    • If you don’t explicitly set a hostname in /etc/postfix/main.cf file, Postfix will use the OS hostname by default, so changing the OS hostname can prevent Postfix from using other hostnames that may be unresolvable.

    • When you add additional domains in iRedMail, you don’t need to change the hostname. This hostname should have an A record, pointing to the IP address of the server and the IP address should have a PTR record, pointing back to the same hostname. This is a good practice to pass spam filters.

  • Thanks for that.
    One question, is there a way to autorenew letsencrypt certificates or is that always a manual task?
    Thanks

  • Maybe you will expand this tutorial to add email aliases via MariaDB? E.g. webmaster, admin.

  • In my /etc/hosts file I have:

    127.0.0.1       localhost
    IP-address   vpsName.mydomain.com vpsName
    
    ::1     localhost ip6-localhost ip6-loopback
    xx02::1 ip6-allnodes
    xx02::2 ip6-allrouters
    IP-address vpsName.providerserver.net vpsName

    Should the second line be after changes? Like this:

    127.0.0.1      mail.mydomain.com localhost
    IP-address   vpsName.mydomain.com vpsName

    And what with IPv6 lines?
    I ask because when I run

    dig -x IP-address +short

    I get:

    vpsName.mydomain.com.
    vpsName.
    vpsName.providerserver.net.

    And I think that something is wrong…

  • How do I create virtual hosts for each sub domain?

  • Hi, Everything seems to be working but I get the following meaages sent to the postmaster:

    netdata notification
    mail.mydomain.com is critical
    mem.available

    ram available = 4.5%
    estimated amount of RAM available for userspace processes, without causing swapping
    ALARM
    system
    FAMILY
    CRITICAL
    SEVERITY

    Is this because my server is only 2gb ram?
    Could this stop emails being sent?

    I am having trouble working out how to monitor things to see if emails are being rejected or sent etc. Any guidance appreciated, thanks

    • On a fresh installed Ubuntu server, the RAM usage is little more than 1GB after installing iRedMail. You might have other software installed that causes such high RAM usage. Use htop to find RAM-hungry programs on your server and stop those services that you don’t need. You can also enable swap space to prevent OOM (Out of Memory) problems.

      If your emails cannot be sent at all, there will be logs generated in /var/log/mail.log and if your emails are rejected, you will receive an automated email from the Postfix daemon.

      • It seems something is being rejected but cant understand why? When I try to register on a list using a form using email: [email protected] I get the folowing mail.log error:

        Jan 23 11:01:54 mail postfix/submission/smtpd[11910]: warning: hostname premium47.web-hosting.com does not resolve to address 68.65.123.240
        Jan 23 11:01:54 mail postfix/submission/smtpd[11910]: connect from unknown[68.65.123.240]
        Jan 23 11:01:55 mail postfix/submission/smtpd[11910]: Anonymous TLS connection established from unknown[68.65.123.240]: TLSv1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)
        Jan 23 11:01:56 mail postfix/submission/smtpd[11910]: NOQUEUE: reject: RCPT from unknown[68.65.123.240]: 554 5.7.1 : Recipient address rejected: Sender is not same as SMTP authenticate username; from= to= proto=ESMTP helo=
        Jan 23 11:01:56 mail postfix/submission/smtpd[11910]: disconnect from unknown[68.65.123.240] ehlo=2 starttls=1 auth=1 mail=1 rcpt=0/1 quit=1 commands=6/7

        • Stephen
          10 months ago

          So is this the main reason emails arent being sent?

          Recipient address rejected: Sender is not same as SMTP authenticate username

        • Stephen
          10 months ago

          I believe its sorted now? I added this to setting.py
          ALLOWED_LOGIN_MISMATCH_SENDERS = [‘[email protected]’]

          Is this safe? Thanks for letting my (pardon the pun) BOUNCE off of you. Much appreciated. for the great post.

    • It seems you are trying to send email from another server using the SMTP submission port but the login name isn’t the same as the sender email address.

      If I were you, I would just create an separate email account for that sender, but you can add exceptions in /opt/iredapd/settings.py. It is safe in my opinion.

      • Thank you, It is working fine now after much frustration. I just need to find the cause of the high ram usage. But at least its working now. Il dig deeper based on your comment above. Thanks again, I couldnt have done this without you.

    • Glad to know it’s working now 🙂

      • Using htop it seems most of the 1.49GB memory being used is used by the following two processes:

        clamav – 31.4% /usr/sbin/clamd –forground=true
        mysql – 18.6% /usr/sbin/mysql –daemonize –pid-file=/run/mysqld/mysqld.pid

        Not sure what that means though.

    • That means ClamAV (Clam Antivirus) is using 31.4% of RAM and MySQL/MariaDB database server is using 18.6% of RAM. This is normal.

      I can see that you are running netdata on your mail server. If you selected all components in the iRedMail setup wizard, your server will use more RAM.

      My iRedMail server is using about 1.1GB RAM. I didn’t install netdata.

  • Thanks Xiao, I will leave it installed for now and see if I can learn from it over the long term. When I get up and running I can easily update the vps at a reasonable cost. So thanks for the help. I do appreciate it.

  • Andrei Valentin Niculae
    10 months ago

    Hi,

    I used your tutorial and everything went smooth until I tried sending an email with a newly created account. In Roundcube I am seeing the following error: “SMTP Error (454): Authentication failed.”

    Looking into postmaster account I can see an email with containing the following:

    Transcript of session follows.
    
     Out: 220 mail.nemesyslabs.ro ESMTP Postfix
     In:  EHLO _
     Out: 250-mail.nemesyslabs.ro
     Out: 250-PIPELINING
     Out: 250-SIZE 15728640
     Out: 250-ETRN
     Out: 250-STARTTLS
     Out: 250-ENHANCEDSTATUSCODES
     Out: 250-8BITMIME
     Out: 250-DSN
     Out: 250 SMTPUTF8
     In:  STARTTLS
     Out: 454 4.7.0 TLS not available due to local problem
     In:  RSET
     Out: 530 5.7.0 Must issue a STARTTLS command first
     In:  QUIT
     Out: 221 2.0.0 Bye
    
    
    For other details, see the local mail logfile

    Can you please give me an idea where I should look and what I need to do to fix this?

    Thank you!

    • This line

      454 4.7.0 TLS not available due to local problem

      indicates that there might be a problem with your TLS configuration in either Postfix or Dovecot.

      • Andrei Valentin Niculae
        10 months ago

        Now I found the error in the Postfix configuration, but another problem appeared. I can send emails but the ones that I should receive don’t arrive in my inbox. I don’t have any error now in the postmaster account. What should I look for?

    • Check /var/log/mail.log file.

      • Andrei Valentin Niculae
        10 months ago

        The file seems to be empty. Is there a know reason why it shouldn’t have any data?

        • Andrei Valentin Niculae
          10 months ago

          Do you have any feedback in regards to what I need to look forward from here? It seems that my emails are sent but the ones that I receive are not arriving in my inbox.

    • Your domain name nemesyslabs.ro doesn’t have a MX record.

  • ckhatton
    10 months ago

    DigitalOcean now allows port 25 by default. They must have had too many complaints and gave up.

  • Thanks for a great howto! It is one of the best out there! So thank you for making it and sharing it!

  • recently i tried to send bulk mails, but gmail and outlook marked mail as spam. Any idea?

  • First of all, thank you very much for your great and very useful work.
    My new installation with 0.9.9 iRedMail work great but… no way to connect from client… no outlook 2019, no Samsung Android mail, no Thunderbird…
    My server is at my home no way nor inside my home network nor outside (I’ve forwarded all necessary ports…).
    Till some days ago, with 0.9.8 all worked fine, after that my SSD crashed and I started from scratch again but with 0.9.9.
    Any idea?
    Thank you
    Aldo

    • Also in local no way to connect to server, using dovecot webmail all works correct

  • And also this one:)

  • Monsieur Apple
    9 months ago

    Thanks for the guide! I got Let’s Encrypt working on my mail server, which is great, though the problem is that I am no longer able to send emails from the same domain as my mail server. For example, like [email protected] to [email protected] I get SMTP error 454: authentication failed when sending though Roundcube. How can I fix this? It seems to have something to do with not finding a certificate, I checked but I think I spelled them all properly. What should I do?

    Feb 14 20:26:51 mail postfix/submission/smtpd[3677]: cannot load Certification Authority data, CAfile="/etc/letsencrypt/live/mail/mail.mydomain.net/chain.pem", CApath="/etc/ssl/certs": disabling TLS support
    Feb 14 20:26:51 mail postfix/submission/smtpd[3677]: warning: TLS library problem: error:02001002:system library:fopen:No such file or directory:../crypto/bio/bss_file.c:74:fopen('/etc/letsencrypt/live/mail/mail.mydomain.net/chain.pem','r'):
    Feb 14 20:26:51 mail postfix/submission/smtpd[3677]: warning: TLS library problem: error:2006D080:BIO routines:BIO_new_file:no such file:../crypto/bio/bss_file.c:81:
    Feb 14 20:26:51 mail postfix/submission/smtpd[3677]: warning: TLS library problem: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib:../crypto/x509/by_file.c:199:
    Feb 14 20:26:51 mail postfix/submission/smtpd[3677]: connect from mail.mydomain.net[127.0.0.1]
    Feb 14 20:26:51 mail roundcube: ERROR: Invalid response code received from server (454)
    Feb 14 20:26:51 mail roundcube: ERROR: Invalid response code received from server (530)
    
  • Hi Xiao,

    Thanks for your incredible guide, i wonder how to change a little thing on my config, but i can not find the way to do it, i would like that the when people type my ip adress in the url bar 162.x.x.x.x it will be redirected directly on https://mail.my-domain.com

    How can i do that ?

    Thanks a lot 🙂

    • Create a new virtual host in /etc/nginx/sites-enabled/ directory.

      sudo nano /etc/nginx/sites-enabled/ip.conf

      Copy and paste the following text into the file.

      server {
              server_name your-server-ip-address;
              listen 80;
              return 301 https://mail.your-domain.com$request_uri;
      }

      Replace with your own IP address and domain name. Save and close the file. Then reload Nginx.

      sudo systemctl reload nginx
  • Hi Xiao,

    I followed your instructions, but i still have this page 🙁

    https://ibb.co/S6ZMGqL

    I searched but i did not find why it was not working …

    Thanks in advance for your help.

    🙂

  • Hello,

    Thank you for this guide it is very well laid out and easy to follow. I was wondering if you could add hot to setup the mailcrypt plugin for Dovecot? It wold be really cool to have the email encrypted at rest on the vps.

    Thanks.

  • I have done everything as per ur tutorial but on final step I got this error. I have copied the error text from console below. will you please review what to do to solve this problem????

    php-xml is already the newest version (2:7.3+69+ubuntu18.10.1+deb.sury.org+2+php7.3).
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:
    
    The following packages have unmet dependencies:
     mariadb-server : Depends: mariadb-server-10.1 (>= 1:10.1.29-6ubuntu2) but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.
    <> Installation failed, please check the terminal output.
    <> If you're not sure what the problem is, try to get help in iRedMail
    <> forum: https://forum.iredmail.org/
    • Please run this command.

       sudo apt install mariadb-server-10.1 mariadb-server
      • please give me a solution. After successfully installing all i am getting error when i go to my roudcube webmail .
        it says database error. and also when i tried to connect on webadmin panle its says Internal Server error.

        DATABASE ERROR: CONNECTION FAILED!
        Unable to connect to the database!
        Please contact your server-administrator.

    • Run the following command to check if you can log into MariaDB server.

      mysql -u root -p

      You need to enter the MariaDB root password.

  • Thank you for making this guide. It helped me quickly setup an email server for one of my clients. Much appreciated for the work you put in! It worked flawlessly without needing any additional configuration.

  • Hi, Salut! Great! Xiao Guo-An (Admin) Can you help me please?

    Error setup SSL certificate. Worked up to add account, less to send and receive messages – don’t.

    What happening if talk/ask (for change IP, because appear in blacklist)
    my ISP to change IPV from v4 in v6, including dynamic IP address , or vice-versa,
    that affect functioning my initial setup mail server? Now does not work anymore. Not at all.

    I must to redone steps by first?
    My mail server starting automatically when I restart Ubuntu?

    I want totally free my mail server hosted by my PC, in Ubuntu desktop 18.04, don’t pay for (“hosted on”)
    DigitalOcean or else.

    Quota:

    David
    5 months ago 
    Reply 
    Will this work with Ubuntu Desktop?
        • 
          Xiao Guo-An (Admin)
          5 months ago 
          Reply 
          To make it work on Ubuntu desktop in your home, you need to 
          1). Have a static IP address, or set up dynamic DNS if your have a dynamic IP address.
          2). Configure port forwarding in your router. (IMAP port 993)
          3). If your ISP blocks port 25, then set up SMTP relay. 
          It’s totally doable, if you are willing to get your hands dirty.
        • 

    3). My ISP says not only port blocks – appear OK.

    1). I have a dynamic IP address . How setup dynamic DNS? – tutorial link.

    2). Configure port forwarding in your router. (IMAP port 993). How – tutorial link. My ISP?

    Why you say “It’s totally doable, if you are willing to get your hands dirty.”, is so hard to do that?

    Thank you!

    PS. I think, it is useful for us to number steps to follow if we are not missing any step.

    • I can’t show you how to set up dynamic DNS or configure port forwarding in router, because of a number of reasons. Actually they are not hard to do. Just search on the Internet.

      If you change IP address, you also need to change the DNS A record. No need to reinstall iRedMail.

    • First, dynamic DNS won’t work on my network. Second, my router user interface is in Chinese. No English is available.

    • Please note that I do not recommended setting up mail server with a dynamic IP address, because your emails are more likely to be put into spam folder. Just think that your IP address changes every few days and you could be using a blaclisted IP address one day. It’s unpredictable.

      If you have dynamic IP address, set up SMTP relay to get better email deliverability.

      • Wtf, what happening, now working again. IRedMail may be updown/offline sometimes?
        Modoboa it is better?
        Can i have simultaneous iRedMail and Modoboa, can work toghether, in parallel?

    • Sorry, I don’t know exactly what you mean by “iRedMail offline”.

      You can’t install Modoboa and iRedMail on the same server. That will create more problems.

      They are equally good, I think.

      • I want to say:
        Initialy work to create new account,
        and Then not work anymore. Not at all.
        I can’t to understand this oscillation behaviour.

      • Hi,

        after talk my ISP support and unblocked ports, working now to send messages

        to [email protected] but not to gmail,

        and not works to send back from them both

    • Sorry, but I forgot to tell you to configure port forwarding for the SMTP port 25, and also port 587.

  • ckhatton
    7 months ago

    How do you set the Let’s Encrypt to auto renew? I am getting firewall errors when I type `certbot renew –dry-run`

    • The certbot package on Ubuntu ships with a systemd timer (/lib/systemd/system/certbot.timer) and a Cron job (/etc/cron.d/certbot). That’s why I didn’t write about certificate auto renewal.

      Sometimes certbot can have weird problems. You can try using another ACME challenge like tls-alpn-01.

  • let’s encrypt failed. tried to disable https. now letsencrpypt wont issue cert for another week after 5 tries.

    • ckhatton
      7 months ago

      It sounds like you have the same problem as me! It reports that the firewall is preventing it from renewing.

      • Yes, that was it. Reinstalled making sure Nguni full was allowed. Ty

        • ckhatton
          7 months ago

          Oh really? Maybe I’ll try that then.

  • You… are absolutely amazing. Thanks, once again, for teaching me something new.

  • ckhatton
    7 months ago

    I am still having letsencrypt problems. I commented out the HTTPS redirect in the “00-default.conf”, and now I get…

    Invalid response from http://mail.ckhatton.com/.well-known/acme-challenge/AJFepDxAdkvW7q0_AO2qrQopXXuTIiVniI_jVSKg1i4 [
    46.101.15.21]: “\r\n404 Not Found.”

  • maximumwarp
    7 months ago

    Hello, I followed this guide and the other to use Mailjet as SMTP relay server and my mail everything works like a charm.
    I installed on a VirtualBox virtual machine with Debian 9.9 as OS.
    I need to use the same virtual machine as web server form my personal website (built with WordPress) and a couple of webapps, I can’t configure a different virtual machine because the real machine isn’t powerful enough to run 2 VMs at same time.
    How must I configure Nginx to host multiple websites? On a clean installation of Debian I follow this guide https://www.techcoil.com/blog/how-to-setup-a-raspberry-pi-web-server-with-raspbian-stretch-lite-nginx-mariadb-and-php-as-the-lemp-stack/ but with iRedMail it doesn’t work…
    I noticed changes in many configuration file, especially in /etc/php/7.0/fpm/pool.d/www.conf (listen = 127.0.0.1:9999 instead of listen = /run/php/php7.0-fpm.sock and others related modifications…)

    • iRedMail comes with a LEMP stack and there’s no need to change PHP configurations. To host multiple websites, you just need to create new virtual host file in /etc/nginx/conf.d/ directory.

  • Webmail from Roundcube works perfectly but I tried to configure a couple of email clients (Android and Windows) and they can’t reach the mail server, do I need to open/port-forward 993 and 587 ports on my modem-router?

    • Yes, if you set up a mail server at your home, you need to port forward 993 and 587 for mail client to login. You also need to port forward 25 to receive email from other mail servers.

  • Alexandru Gagea
    7 months ago

    Hello,

    I’m having issues with my DKIM record. I did exactly as instructed however, the command : sudo amavisd-new testkeys results in invalid. The test does not pass.

    Iredmail was installed on an ec2 instance.

    Please help.

    • It’s likely because you didn’t enter your DKIM record correctly in your DNS manager.

      • Alexandru Gagea
        7 months ago

        Solved it. I had to make the string on a single line. The current issue is with the SPF record. I’ve added in my DNS Manager the following : v=spf1 mx ~all and it says that i’m not fully authenticated. What am i missing ? I created the rule in Route 53.

  • Hello

    what is the exact difference with the article https://www.linuxbabe.com/mail-server/ubuntu-16-04-iredmail-server-installation

    Sorry I am newbie with iredmail servers, I need your help.

    Thanks

    • They are no major differences between the two articles. One is for ubuntu 16.04 and this article is for ubuntu 18.04.

      • Thanks Xiao

        I have read through this article , it is great. I have some doubts about hostname and mx record value.

        1. the hostname must be the same with mx record value ?
        2. the hostname value must be a real FQDN domain name ? can I use something like “demo.demo.demo” ?

    • The hostname can be different than the MX record value.
      The hostname must be a real FQDN domain name, because many mail servers check the A record of the hostname. Hostname without a valid A record increases your chance of landing in spam folder or being rejected outright.

      • I have install it succesully , thanks xiao.

        I can see the tips in system dump like this

        * – Roundcube webmail: https://mail.example.com/mail/
        * – netdata (monitor): https://mail.example.com/netdata/
        * – Web admin panel (iRedAdmin): https://mail.example.com/iredadmin/

        I can see everything from iredmail resides in sub domain mail.example.com, is it possible to make it in root domain ?

        * – Roundcube webmail: https://example.com/mail/
        * – netdata (monitor): https://example.com/netdata/
        * – Web admin panel (iRedAdmin): https://example.com/iredadmin/

    • Yes, you can.

      Just replace mail.example.com with example.com in /etc/nginx/sites-enabled/mail.example.com.conf file and obtain a TLS certificate for example.com with Certbot, then reload Nginx.

  • Hello

    if I do a fresh installation, how can I achive this ? I can see this tutoiral is for subdomain

  • Maxim Ellenberg
    5 months ago

    Very good article!

  • Hi Mr. Xiao,

    Very good article, how to make mail list or alias?

    Thank You very Much

    • iRedMail integrates mlmmj as the mailing list manager. However, it requires you to purchase a Pro account to use it in the web-based admin panel. If you don’t like spending money, I recommend using the Mailtrain self-hosted mailing list app.

      Creating alias in the web-based admin panel also requires purchasing a Pro account. However, you can create alias in the SQL database console. After creating alias, you can create the corresponding identity in RoundCube webmail, so you can use the alias address in the From header when replying emails.

    • Hi Mr.Xiao,

      thank you for your information, please provide information for creating email groups? can you use mailtrain?

      Thx,

  • Jeremy Willson
    5 months ago

    Hello linuxbabe
    Thank you for your tutorial for a ubuntu mail server. I am attempting to install using a clean Kubuntu 9.04.
    However, I get a message telling me of a failure to install. (see last few lines of install info below telling about missing packages.

    [ INFO ] Installing package(s): postfix postfix-pcre libsasl2-modules mariadb-client mariadb-server postfix-mysql libdbd-mysql-perl php-cli php-fpm php-json php-gd php-curl mcrypt php-intl php-xml php-mbstring php-mysql nginx-full dovecot-imapd dovecot-pop3d dovecot-lmtpd dovecot-managesieved dovecot-sieve dovecot-mysql amavisd-new libcrypt-openssl-rsa-perl libmail-dkim-perl clamav-freshclam clamav-daemon spamassassin altermime arj nomarch cpio lzop cabextract p7zip-full rpm ripole libmail-spf-perl unrar-free pax lrzip mlmmj sogo sogo-activesync sope4.9-gdl1-mysql python-sqlalchemy python-dnspython python-mysqldb python-pymysql python-jinja2 python-netifaces python-webpy python-beautifulsoup python-lxml python-pycurl python-requests uwsgi uwsgi-plugin-python python-bcrypt fail2ban zlib1g libuuid1 libmnl0 curl lm-sensors netcat bzip2 acl patch cron tofrodos logwatch unzip bsdutils liblz4-tool
    Reading package lists...
    Building dependency tree...
    Reading state information...
    Package ripole is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    
    Package python-webpy is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    
    E: Package 'ripole' has no installation candidate
    E: Unable to locate package sogo-activesync
    E: Unable to locate package sope4.9-gdl1-mysql
    E: Couldn't find any package by glob 'sope4.9-gdl1-mysql'
    E: Couldn't find any package by regex 'sope4.9-gdl1-mysql'
    E: Package 'python-webpy' has no installation candidate
    <> Installation failed, please check the terminal output.
    <> If you're not sure what the problem is, try to get help in iRedMail
    <> forum: https://forum.iredmail.org/
    [email protected]:~/iRedMail-0.9.9$ 
    

    I did try using apt-get to install python-webpy, but it too failed as below.

    [email protected]:~/iRedMail-0.9.9$ sudo apt-get install python-webpy
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Package python-webpy is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    

    E: Package ‘python-webpy’ has no installation candidate
    [email protected]:~/iRedMail-0.9.9$

    Also, the script failed because iRedMail-0.9.8 wasn’t the latest, so I had to change the commands to iRedMail-0.9.9

    • iRedMail only supports LTS release of Ubuntu (Currently Ubuntu 16.04 & Ubuntu 18.04). I won’t try to install iRedMail on non-LTS Ubuntu to create unnecessary problems.

  • michaelIXOT
    4 months ago

    These were excellent instructions. With that said, now that it’s time to renew certbot certs I’m getting the following error:
    ‘Attempting to renew cert (mail..com) from /etc/letsencrypt/renewal/mail.ironbridgeenterprise.com.conf produced an unexpected error: Missing command line flag or config entry for this setting:
    Select the webroot for mail.ironbridgeenterprise.com:
    Choices: [‘Enter a new webroot’, ‘/var/www/html’]

    I want to try setting the webroot value, what should we use for iredmail?

  • Alexandru Gagea
    4 months ago

    Hi,

    All of the sudden my iredmail server stopped working.. I have no idea why and how. I did make a change in the iredapd settings.py. I’ve added an email address to ALLOWED_LOGIN_MISMATCH_SENDERS. and restarted iredapd. After this restart everything worked fine.
    I don’t really know what to check … Any ideas ?

  • Alexandru Gagea
    4 months ago

    The issue is now solved. The cause was the linux firewall which for some reason stopped.

  • Gerald Blondel
    3 months ago

    Amazing page! Thanks a lot.
    fyi, there is absolutely no problem on digitalocean; but Google Cloud is the one blocking port 25! I gave up using them.

    • I did an iRedMail install on DigitalOcean at several data centers (San Francisco, New York, Bangalore). Port 25 (outbound) is blocked and DigitalOcean refused to unblock it.

  • Hi, Xiao…
    I am a newbie in Linux OS, I found your web so much knowledge and useful for me. I just setup iRedmail in ubuntu 18.04 lts with Vultr server that had recommended by you and follow your instruction. However, I had face a problem in installing certbot Letsencrypt. Here is what I get:

    The following errors were reported by the server:

    Domain: mail.ohsemmarketing.com
    Type: connection
    Detail: Fetching
    https://mail.ohsemmarketing.com/.well-known/acme-challenge/qD7xuY2O1B_NOyEsqm7pPdFaF00Hy51Nmmo_yDSpTfU:
    Timeout during connect (likely firewall problem)

    To fix these errors, please make sure that your domain name was
    entered correctly and the DNS A/AAAA record(s) for that domain
    contain(s) the right IP address. Additionally, please check that
    your computer has a publicly routable IP address and that no
    firewalls are preventing the server from communicating with the
    client. If you’re using the webroot plugin, you should also verify
    that you are serving files from the webroot path you provided.
    – Your account credentials have been saved in your Certbot
    configuration directory at /etc/letsencrypt. You should make a
    secure backup of this folder now. This configuration directory will
    also contain certificates and private keys obtained by Certbot so
    making regular backups of this folder is ideal.

    For the A & AAAA records for my Ipv4 & Ipv6 had been recorded in DNS.So I think the only error is in firewall. How can I fix this?Thank you

    • It’s likely because the Nginx virtual host didn’t enable IPv6. To enable IPv6 in Nginx virtual host. Open the /etc/nginx/sites-enabled/000-default.conf file

      sudo nano /etc/nginx/sites-enabled/000-default.conf

      and find the following line.

      #listen [::]:80;

      Remove the # symbol to enable IPv6.

      listen [::]:80;

      Save and close the file. Then edit the SSL virtual host /etc/nginx/sites-enabled/00-default-ssl.conf. Add the following line.

      listen [::]:443 ssl http2;

      Save and close the file. Then test Nginx configuration.

      sudo nginx -t

      If the test is successful, reload Nginx for the change to take effect.

      sudo systemctl reload nginx

      Next, run the certbot command to obtain TLS certificate.

      sudo certbot certonly --webroot --agree-tos --email your-email-address -d mail.your-domain.com -w /var/www/html/
  • Ok,thank you so much Xiao. As I had followed your instruction to enable the 80 port for ipV6, it still could not install the certificate. However I had try to remove the AAAA record from my server’s ipv6. Install the certbot using ipv4 A records,it works again. Just don’t know why ipv6 from this server had been blocked by Letsencrypt? Or letsencrypt blocked port 80?

    • If your mail server hostname has an IPv6 record, Let’s Encrypt validation server will try to reach your mail server via IPv6 protocol. If there’s no IPv6 record, it will do so via IPv4 protocol. Let’s Encrypt does not block anything. If you see errors when trying to obtain TLS certificate, it’s almost always due to something on your own server.

      It’s fine to only use IPv4 address on your mail server.

  • Alexandru Gagea
    2 months ago

    Hello,

    I’m trying to renew my certificate and I get the bellow error when using “sudo certbot renew”.

    Attempting to renew cert (my.domain) from /etc/letsencrypt/renewal/mydomain.conf produced an unexpected error: Missing command line flag or config entry for this setting: Select the webroot for my.domain:
    Choices: [‘Enter a new webroot’, ‘var/www/html’]

    Any ideas would be much appreciated.

    Thank you

  • Alexandru Gagea
    2 months ago

    I’ve solved the above issue myself. I’

    If anyone else will encounter this issue its because of multiple domains. So to fix it you have to go to /etc/letsencrypt/renewal/example.conf and under section [[webroot_map]] add the second domain.

    [[webroot_map]]
    mail.domain1.com = var/www/html
    mail.domain2.com = var/www/html

    After you save the file, run again sudo certbot renew –dry-run to see if the issue its fixed.
    The post that helped me fix this issue also says thats it’s a good idea to restart nginx after you renew the certificate.

    service nginx reload

    • Robert Aitken
      1 month ago

      Alexandru, Thanks for the pointers. I’ve been searching for days to find out how to solve this. Only suggestion would be to change “/etc/letsencrypt/renewal/example.conf ” to “/etc/letsencrypt/renewal/.conf” just in case someone thinks they should have an example.conf.

      Xiao Guoan, Thanks for the easy to follow instructions. I had my mail server up and running on a virtual machine in a couple off days. Second day was finding out why my external IP was getting blacklisted. Once sorted it ran wonderfully.

      Thanks Both of you.

  • Hi! I want to make a website where users can create an email address @mywebsite.com I want them to be able to create this on their own upon entering the site. Anyone knows if I can use this tool to do this. How? Thanks!

  • Massimiliano Iavazzo
    1 month ago

    Hello, just after installation by iRedmail Easy and making all records in DNS, I can sent email but not receive it with following error:

    554 5.7.1 : Relay access denied

  • Hi Xiao.
    I am in the process of trying your guide. Thanks for sharing.
    I encountered errors related to nginx while installing iRedMail and it did not finish as seen in your guide. In “/var/log/nginx/error.log”
 I found “(socket() [::]:80 failed (97: Address family not supported by protocol)
”. It seems nginx would like to have IPv6 enabled during installation – just a guess. I disabled IPv6 before installing iRedMail.
    I changed /etc/nginx/sites-available/default
 – and restarted
    #listen [::]:80;
    Running the installation again did now succeed and I will proceed.

  • Hi Xiao,
    your instructions were perfect! Exectly what I was looking for, in order to set up my own mail server – thank you!

  • I followed all the steps properly. I am not able to login with the admin account. I am directly copying the password from iRedmail.tips so I am sure I am not making any mistakes. I tried the setup 3-4 times now. Every time I am getting the same issue.

  • Phillip Katete
    2 weeks ago

    Thank you for this article. I installed this on a VPS with Ubuntu 18.04, 1GB ram, 1GB drive and it is working fabulously, but that was not the case initially. Memory consumption (including swap usage) and CPU utilisation were extremely high to an extent that both the ssh and web interfaces were barely useable. I noticed from the logs (and htop) that antivirus and netdata activity was high so this is what I did.

    1. I run sa-update (to update spam assassin) then restarted it.
    2. I edited the netdata conf to change the frequency of polling from 3 seconds to 300 (five minutes), then restarted it
    3. I also removed the greylisting as this was not only creating queues but was also blocking legitimate email

    I did some other changes to postfix configuration but I do not think those affected the performance of the VPS. More importantly, it is now working absolutely fine with memory usage down to around 30% on average with swap fluctuating between20% and 45%.

    Just one question. Why does fail2ban keep jailing my IP when I try to access email on my iPhone? I completed setting up configuration for outlook but I am waiting to try it out until I can get to the bottom of why fail2ban keeps jailing my IP.

    • Edit the /etc/fail2ban/jail.local file and add your own IP address to the ignoreip list, then restart fail2ban.

      • Phillip Katete
        2 weeks ago

        This is not a good work-around as this may change depending on where I am. At the moment it is blocking my home IP because my iphone is on wifi but this will not be the case if I am not home.
        I really need to find out why rather than how to fix it – is there a ‘greylisting’ type setting or a less aggressive mode for fail2ban?

    • You can check the fail2ban log (/var/log/fail2ban.log) to find out which Fail2ban jail banned your IP address.

      You can also setting up a VPN server on your mail server and always use VPN on your computer and mobile phone, so you will have the same IP address no matter where you are.

      • Phillip Katete
        2 weeks ago

        I was jailed in the iptables chain ‘f2b-dovecot’ so I suppose that is dovecot – any clues on what to look for in the log (I recall there was a log about icmq or something)?

    • The fail2ban log is very easy to read. For example, the following line indicates the [postfix] jail banned the IP address 61.186.65.48

      2019-11-02 11:59:50,528 fail2ban.actions        [667]: NOTICE  [postfix] Ban 61.186.65.48
      • Phillip Katete
        2 weeks ago

        I must have switched off the fail2ban logs as I have nothing in there since 31st Oct. In any case, I believe this is an authentication failure – so the question is: What credentials do we apply in the Outgoing Mail Server? I have entered the same credentials for a user account I created in iRedAdmin (not the postmaster account) for both the Incoming and Outgoing servers but I suspect the latter is the one causing issues and getting my IP jailed. Thoughts?

    • You should use the same email address and password for incoming and outgoing email server.

      If your IP address is jailed in the iptables f2b-dovecot chain, I think you can not authenticate with Dovecot IMAP server, which is the incoming email server.

      You can check the mail log (/var/log/mail.log) to find other clues.

      • Phillip Katete
        2 weeks ago

        This is a chicken and egg sort of thing since I only get jailed when I ‘provide incorrect credentials’ and fail to authenticate. I think the iPhone mail client keeps retrying forever (even when it gets my IP jailed!).
        PS: like I mentioned, something turned the logging off by mistake … logs are empty since they were recycled. I tried to set permissions to all read and write to no avail … maybe I need to reboot.

    • You can flush the f2b-dovecot chain with the following command.

      sudo iptables -F f2b-dovecot

      So your IP address will be released from jail.

      • Phillip Katete
        2 weeks ago

        Yes – I have been doing that, but that does not solve the underlying issue (which is why I posted) of why I am failing authentication with dovecot when I have the correct credentials entered.

  • Hi Xiao … Greetings from Panama
    I have to develop a mail server project.
    I skip steps 1 and 2 since I have to run it locally.
    I installed only that when writing
      https: //mail.miip/iredadmin/ doesn’t show me anything.
    Thanks in advance.
    Skipping steps 1 and 2 affects me ????

    does not show me if ip the ip address

  • Christopher Gilchrist
    1 week ago

    Ok Guys this is what I did after two weeks of fighting with this Mail Server running internally at home – now stable and monitoring for a few days

    Hardware Specifications – Old Slow Computer but stable reliable and quick enough
    HP Mini Notebook 21-4000 32 Bit 2 CPUs 4GB Memory 480GB SSD
    Operating System Ubuntu Mate 18.04.3 Clean Install

    Creation of MX and SPF Records

    *.christophergilchrist.co.uk A 81.174.138.41 120 Disable IPv4 Wildcard Alias
    *.christophergilchrist.co.uk AAAA 120 Disable IPv6 Wildcard Alias
    mx.christophergilchrist.co.uk A 81.174.138.41 120
    christophergilchrist.co.uk MX mx.christophergilchrist.co.uk [Priority: 10] 90
    christophergilchrist.co.uk SPF v=spf1 mx mx:christophergilchrist.co.uk -all 120

    Internet Firewall Router Setup and Port Forwarding to internal mx machine

    IMAP port forward to mx

    Type Router Port mx Port
    TCP 143 143

    Pop3 SSL TLS
    Type Router Port mx Port
    TCP 110 110
    TCP 995 995

    SMTP SSL TLS
    Type Router Port mx Port
    TCP 25 25
    TCP 587 587

    Installation on HP Mini Notebook – clean install of Ubuntu Mate 32 BIt 18.04.03

    Pre requisites after clean install

    Edit your etc hosts file for loopback and internal network card interfaces – DO BOTH in the order shown OTHERWISE iRedmail falls over after a day and a half and messes everything up.

    sudo vi /etc/hosts

    127.0.1.1 mx.christophergilchrist.co.uk mx localhost localhost.localdomain
    192.168.1.69 mx.christophergilchrist.co.uk mx localhost localhost.localdomain

    Make sure you have all Ubuntu Default Repositories Active!
    If not it will not install clamav properly

    Install the following packages

    sudo apt update
    sudo apt upgrade
    sudo apt-get install ssh
    sudo apt-get install dksm

    Open up your internal firewall ports

    sudo ufw allow 22/tcp
    sudo ufw allow 25/tcp
    sudo ufw allow 80/tcp
    sudo ufw allow 110/tcp
    sudo ufw allow 443/tcp
    sudo ufw allow 587/tcp
    sudo ufw allow 995/tcp

    Download https://www.iredmail.org/download.html Stable Version 0.9.9

    Follow the install guide from
    https://docs.iredmail.org/install.iredmail.on.debian.ubuntu.html at this stage – Download the latest release of iRedMail

    Do it as user with sudo privileges it should install all packages cleanly and properly and complete in around 45 minutes – 1 hour

    Check the mail.log for any errors

    cd /var/log
    less mail.log

    After the iRedmail install is complete reboot the machine you should be able to goto

    https://mx.christophergilchrist.co.uk/mail
    https://mx.christophergilchrist.co.uk/iredadmin

    I also had problems with International Policy rejecting @outlook.com @gmail.com
    There are admin scripts to reset the banned top level domains and do other admin tasks.

    Have fun.

    Chris

    Chris

  • Mag. Martin Heiduk
    1 week ago

    Hi, Vultr lures you into believing, that you can use their service, since they block port 25 after you have used it for a few times. Their policy states, that it CAN NOT BE USED FOR DOUBLE-OPT-IN-MAILS !!! And they refuse to unblock it!!!

  • Jason Sackett
    1 week ago

    Xiao Guoan,
    I followed this guide and got every step working, and would LOVE to see a guide to add encryption-at-rest to the mail folders (dovecot mail-crypt-plugin easy guide?). Even a quick and dirty one covering the main path would be great.
    Thank you,
    Jason

  • Ramon Silva
    5 days ago

    Hi Xiao,

    before (Step 9: Improving Email Deliverablity), thunderbird was able to connect send and receive emails from other computers. but after I complete all the steps, thunderbird was not able to connect anymore, I just see the following errors in mail.log:

    Nov 14 16:56:37 mail postfix/submission/smtpd[5210]: connect from unknown[158.116.186.2]
    Nov 14 16:56:37 mail postfix/submission/smtpd[5210]: Anonymous TLS connection established from unknown[158.116.186.2]: TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
    Nov 14 16:56:40 mail postfix/submission/smtpd[5210]: warning: unknown[158.116.186.2]: SASL PLAIN authentication failed:
    Nov 14 16:56:46 mail postfix/submission/smtpd[5210]: warning: unknown[158.116.186.2]: SASL LOGIN authentication failed: UGFzc3dvcmQ6

    do you think ‘the Improving Email Deliverablity’ configuration is blocking thunderbird to send emails?

    regards,

  • Tajinder
    1 min ago

    Please make a guide to create mutliple users using txt file on iredmail step by step. I will become very happy

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • If you ask me more than 5 questions, I expect you to make a donation, or I would stop answering your questions.