Part 2: Install Dovecot IMAP server on Ubuntu & Enable TLS Encryption

This is part 2 of building your own secure email server on Ubuntu tutorial series. In part 1, we showed you how to set up a basic Postfix SMTP server. In this tutorial, we are going to configure our email server so that we can receive and send emails using a desktop email client like Mozilla Thunderbird or Microsoft Outlook.

To be able to send emails using a desktop email client, we need to do a little bit configuration on Postfix. To receive emails using a desktop email client, we can install an open-source IMAP server named Dovecot on Ubuntu server. And to encrypt our communications, we need a TLS certificate.

Open Ports in Firewall

Ubuntu doesn’t enable firewall by default. If you have enabled the UFW firewall, then you need to run the following command to open email related ports in firewall.

sudo ufw allow 80,443,587,465,143,993/tcp

If you use POP3 to fetch emails (I personally don’t), then also open port 110 and 995.

sudo ufw allow 110,995/tcp

Securing Email Server Traffic with TLS Certificate

When we configure a desktop email client, enabling encryption is always a good idea. We can easily obtain a free TLS certificate from Let’s Encrypt. Issue the following commands to install Let’s Encrypt client (certbot) on Ubuntu server from the default software repository.

sudo apt install certbot

If you don’t have a web server running yet, I recommend you install one (Apache or Nginx), because it’s easier to obtain and install TLS certificate with a web server than using other methods. And in a later tutorial, I will show you how to set up webmail, which requires running a web server.

If you use Apache web server, you need to install the Apache plugin. (The following command will install Apache web server if it’s not already installed on your system.)

sudo apt install python3-certbot-apache

If you use Nginx web server, then install the Nginx plugin. (The following command will install Nginx web server if it’s not already installed on your system.)

sudo apt install python3-certbot-nginx

Obtaining TLS Certificate with Apache Web Server

You need to have an Apache virtual host for mail.your-domain.com before obtaining Let’s Encrypt TLS certificate. Create the virtual host file:

sudo nano /etc/apache2/sites-available/mail.your-domain.com.conf

Then paste the following text into the file.

<VirtualHost *:80>        
        ServerName mail.your-domain.com

        DocumentRoot /var/www/mail.your-domain.com
</VirtualHost>

Save and close the file. Then create the web root directory.

sudo mkdir /var/www/mail.your-domain.com

Set www-data (Apache user) as the owner of the web root.

sudo chown www-data:www-data /var/www/mail.your-domain.com -R

Enable this virtual host.

sudo a2ensite mail.your-domain.com.conf

Reload Apache for the changes to take effect.

sudo systemctl reload apache2

Once virtual host is created and enabled, run the following command to obtain and install Let’s Encrypt TLS certificate.

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d mail.your-domain.com

Substitute the red text with your actual data. You should see the following which means the certificate is successfully obtained. You can also see the directory under which your cert is stored.

obtain-a-ssl-certificate-from-lets-encrypt

Obtaining TLS Certificate with Nginx Web Server

You need to have an Nginx virtual host for mail.your-domain.com before obtaining Let’s Encrypt TLS certificate. Create the virtual host file:

sudo nano /etc/nginx/conf.d/mail.your-domain.com.conf

Next, paste the following text into the file.

server {
      listen 80;
      listen [::]:80;
      server_name mail.your-domain.com;

      root /var/www/mail.your-domain.com/;

      location ~ /.well-known/acme-challenge {
         allow all;
      }
}

Save and close the file. Then create the web root directory.

sudo mkdir /var/www/mail.your-domain.com/

Set www-data (Nginx user) as the owner of the web root.

sudo chown www-data:www-data /var/www/mail.your-domain.com -R

Reload Nginx for the changes to take effect.

sudo systemctl reload nginx

Once the virtual host is created and enabled, run the following command to obtain and install Let’s Encrypt certificate with Nginx plugin.

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d mail.your-domain.com

You should see the following which means the certificate is successfully obtained. You can also see the directory under which your cert is stored.

postfix tls letsencrypt

Enable Submission Service in Postfix

To send emails from a desktop email client, we need to enable the submission service of Postfix so that the email client can submit emails to Postfix SMTP server. Edit the master.cf file.

sudo nano /etc/postfix/master.cf

In submission section, uncomment or add the following lines. Please allow at least one whitespace (tab or spacebar) before -o.  In postfix configurations, a preceding whitespace character means that this line is continuation of the previous line. (By default the submission section is commented out. You can copy the following lines and paste them into the file, so you don’t have to manually uncomment or add new text.)

submission     inet     n    -    y    -    -    smtpd
 -o syslog_name=postfix/submission
 -o smtpd_tls_security_level=encrypt
 -o smtpd_tls_wrappermode=no
 -o smtpd_sasl_auth_enable=yes
 -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
 -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
 -o smtpd_sasl_type=dovecot
 -o smtpd_sasl_path=private/auth

The above configuration enables the submission daemon of Postfix and requires TLS encryption. So later on our desktop email client can connect to the submission daemon in TLS encryption. The submission daemon listens on TCP port 587. STARTTLS is used to encrypt communications between email client and the submission daemon.

Microsoft Outlook mail client only supports submission over port 465. If you are going to use Microsoft Outlook, then you also need to enable submission service on port 465 by adding the following lines in the file.

smtps     inet  n       -       y       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
  -o smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
  -o smtpd_sasl_type=dovecot
  -o smtpd_sasl_path=private/auth

Enable Submission Service in Postfix

Save and close the file.

Hint: The SMTP protocol is used when an email client submits emails to an SMTP server.

Next, we need to specify the location of TLS certificate and private key in Postfix configuration file. Edit main.cf file.

sudo nano /etc/postfix/main.cf

Edit the TLS parameter as follows:

smtpd_tls_cert_file=/etc/letsencrypt/live/mail.your-domain.com/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/mail.your-domain.com/privkey.pem
smtpd_tls_security_level=may 
smtpd_tls_loglevel = 1
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache

smtp_tls_security_level = may
smtp_tls_loglevel = 1
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

#Enforce TLSv1.3 or TLSv1.2
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtpd_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtp_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1

Your Let’s Encrypt certificate and private key are stored under /etc/letsencrypt/live/mail.your-domain.com/ directory.

postfix tls parameters

Save and close the file. Then restart Postfix.

sudo systemctl restart postfix

If you run the following command, you will see Postfix is now listening on port 587 and 465.

sudo netstat -lnpt | grep master

postfix submission port 587 smtps port 465

Installing Dovecot IMAP Server

Enter the following command to install Dovecot core package and the IMAP daemon package on Ubuntu server.

sudo apt install dovecot-core dovecot-imapd

If you use POP3 to fetch emails, then also install the dovecot-pop3d package.

sudo apt install dovecot-pop3d

Check Dovecot version:

dovecot --version

Sample output:

2.2.22 (fe789d2)

Enabling IMAP/POP3 Protocol

First, edit main config file.

sudo nano /etc/dovecot/dovecot.conf

Add the following line to enable IMAP protocol.

protocols = imap

If you use POP3 to fetch emails, then also add POP3 protocol.

protocols = imap pop3

Save and close the file.

Configuring Mailbox Location

By default, Postfix and Dovecot use mbox format to store emails. Each user’s emails are stored in a single file /var/mail/username. You can run the following command to find the mail spool directory.

postconf mail_spool_directory

Sample output:

mail_spool_directory = /var/mail

However, nowadays it’s almost always you want to use the Maildir format to store email messages. The config file for mailbox location is /etc/dovecot/conf.d/10-mail.conf.

sudo nano /etc/dovecot/conf.d/10-mail.conf

The default configuration uses mbox mail format.

mail_location = mbox:~/mail:INBOX=/var/mail/%u

Change it to use the Maildir format. Email messages will be stored under the Maildir directory under each user’s home directory.

mail_location = maildir:~/Maildir

We need to add the following line in the file. (On Ubuntu 18.04 and 20.04, this line is already in the file.)

mail_privileged_group = mail

Save and close the file. Then add dovecot to the mail group so that Dovecot can read the INBOX.

sudo adduser dovecot mail

Configuring Authentication Mechanism

Edit the authentication config file.

sudo nano /etc/dovecot/conf.d/10-auth.conf

Uncomment the following line.

disable_plaintext_auth = yes

It will disable plaintext authentication when there’s no SSL/TLS encryption. And if you want to use full email address (username@your-domain.com) to login, add the following line in the file.

auth_username_format = %n

Otherwise, you are able to login with username only (without @your-domain.com). Next, find the following line.

auth_mechanisms = plain

This line only enables the PLAIN authentication mechanism. LOGIN is another authentication mechanism you probably want to add to support older email clients.

auth_mechanisms = plain login

Save and close the file.

Configuring SSL/TLS Encryption

Next, edit SSL/TLS config file.

sudo nano /etc/dovecot/conf.d/10-ssl.conf

Change ssl = yes to ssl = required to enforce encryption.

ssl = required

Then specify the location of your SSL/TLS cert and private key. Don’t leave out the < character. It’s necessary.

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

Find the following line.

ssl_prefer_server_ciphers = no

It’s a good practice to prefer the server’s order of ciphers over client’s. So change the value to yes.

ssl_prefer_server_ciphers = yes

We can also disable SSLv3, TLSv1 and TLSv1.1 by adding the following line.

ssl_protocols = !SSLv3 !TLSv1 !TLSv1.1

Note: if you are using Dovecot 2.3.x or above, then you should add the following line instead, which will force Dovecot to use TLSv1.2 or TLSv1.3.

ssl_min_protocol = TLSv1.2

SASL Authentication Between Postfix and Dovecot

Edit the following file.

sudo nano /etc/dovecot/conf.d/10-master.conf

Change service auth section to the following so that Postfix can find the Dovecot authentication server.

service auth {
    unix_listener /var/spool/postfix/private/auth {
      mode = 0660
      user = postfix
      group = postfix
    }
}

Save and close the file.

Auto-create Sent and Trash Folder

Edit the below config file.

sudo nano /etc/dovecot/conf.d/15-mailboxes.conf

To auto-create a folder, simply add the following line in the mailbox section.

auto = create

Example:

 mailbox Trash {
    auto = create
    special_use = \Trash
 }

Some common folders you will want to create includes: Drafts, Junk, Trash and Sent. These folders will be created at the user’s home directory. After you save and close all above config files, restart Dovecot.

sudo systemctl restart dovecot

Dovecot will be listening on port 143 (IMAP) and 993 (IMAPS), as can be seen with:

sudo netstat -lnpt | grep dovecot

ubuntu dovecot imap server 143 993

If there’s a configuration error, dovecot will fail to restart, so it’s a good idea to check if Dovecot is running with the following command.

systemctl status dovecot

We also need to restart Postfix to allow the LOGIN authentication mechanism.

sudo systemctl restart postfix

Using Dovecot to Deliver Email to Message Store

By default, Postfix uses its builtin local delivery agent (LDA) to move inbound emails to the message store (inbox, sent, trash, Junk, etc). We can configure it to use Dovecot to deliver emails, via the LMTP protocol, which is a simplified version of SMTP. LMTP allows for a highly scalable and reliable mail system. This step is required if you want to use the sieve plugin to filter inbound messages to different folders.

Install the Dovecot LMTP Server.

sudo apt install dovecot-lmtpd

Edit the Dovecot main configuration file.

sudo nano /etc/dovecot/dovecot.conf

Add lmtp to the supported protocols.

protocols = imap lmtp

Save and close the file. Then edit the Dovecot 10-master.conf file.

sudo nano /etc/dovecot/conf.d/10-master.conf

Change the lmtp service definition to the following.

service lmtp {
 unix_listener /var/spool/postfix/private/dovecot-lmtp {
   mode = 0600
   user = postfix
   group = postfix
  }
}

Next, edit the Postfix main configuration file.

sudo nano /etc/postfix/main.cf

Add the following lines at the end of the file. The first line tells Postfix to deliver emails to local message store via the dovecot LMTP server.  The second line disables SMTPUTF8 in Postfix, because Dovecot-LMTP doesn’t support this email extension.

mailbox_transport = lmtp:unix:private/dovecot-lmtp
smtputf8_enable = no

Save and close the file. Finally, restart Postfix and Dovecot.

sudo systemctl restart postfix dovecot

Configure Desktop Email Client

Now open 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 143 and STARTTLS. 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.

ubuntu postfix dovecot letsencrypt

Hint: You can also use port 993 with SSL/TLS encryption for IMAP, and use port 465 with SSL/TLS encryption for SMTP.

You should now be able to connect to your own email server and also send and receive emails with your desktop email client!

We use local Unix accounts as email addresses, as we did in part 1. For example, if you have a user called user1 on your Ubuntu server, then you have an email address: user1@your-domain.com, and the password for the email address is the same password for the user1 user. To create a local Unix account, run

sudo adduser user1

Troubleshooting Tips

If you can’t log into your mail server from a desktop mail client, scan your mail server to find if the ports are open. Note that you should run the following command from another Linux computer or server. If you run it on your mail server, then the ports will always appear to be open.

sudo nmap mail.your-domain.com

And check if Dovecot is running.

systemctl status dovecot

You can also check the mail log (/var/log/mail.log), which may give you some clues. If Dovecot fails to start, the error might not be logged to the /var/log/mail.log file, you can run the following command to see what’s wrong.

sudo journalctl -eu dovecot

For example, some folks may have the following error in the journal.

doveconf: Fatal: Error in configuration file /etc/dovecot/conf.d/10-master.conf line 78: Unknown setting

Most of the time, it’s a simple syntax error, like a missing curly bracket. Open the configuration file, go to the specified line and fix the error.

Auto-Renew TLS Certificate

You can create Cron job to automatically renew TLS certificate. Simply open root user’s crontab file.

sudo crontab -e

If you use Apache web server, add the following line at the bottom of the file.

@daily certbot renew --quiet && systemctl reload postfix dovecot apache2

If you are using Nginx web server, then add the following line.

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

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

Wrapping Up

I hope this article helped you set up Postfix and Dovecot on Ubuntu server. In part 3, I will show you how to create virtual mailboxes.

Rate this tutorial
[Total: 45 Average: 4.3]

183 Responses to “Part 2: Install Dovecot IMAP server on Ubuntu & Enable TLS Encryption

  • jubakala
    2 years ago

    Finally, a tutorial that tells everything that’s needed, not only parts of it. And finally, after about 12 hours of trying, I have a working email-server. So THANKS a lot!

    • I m looking for a reliable source which helps me to setup mail server (Ubuntu 19.10)
      This seems better I will try with this….

      Looking for suggestions from all friends
      Thanks

  • This is THE best postfix/dovecot tutorial on the web. Thank you very much for posting. You covered a lot of material in great detail, but there are still a few parts that I’m unclear on.

    When adding your mail account to your mail client, how do you know what the password is? We didn’t set a password for SMTP authentication in the walkthrough. If my Ubuntu user account is ‘admin’, and my email is admin@example.com, do I just use my local ‘admin’ account password to connect my mail client to my new email account?

    What if, in my specific case, my local Ubuntu login is ‘admin’, but I want the email address “user1@example.com” to be the default for all incoming and outgoing mail? Do I need to create a “user1” local user account on Ubuntu? I’ve send some test emails from the “user1@example.com” account and the SPF/DKIM checks are failing. DKIM only passes the check when I send mail from my “admin@example.com” account.

    • Well, I continued working at it and I answered one of my questions. Yes, each email account has to have a local user account on the Ubuntu server in order to have email. I have successfully added my accounts on my Android email application. Still looking into the other issue about the “user1@example.com” failing DKIM (and therefore getting detected as spam).

    • So after some research and trial/error since my last post, I’m still having problems with DKIM. When I email the port25.com test system from the user account that I followed this guide from, I get a pass on everything. When I email from another user on the system and get a report form port25.com, everything except DKIM passes.

      If I send mail from my root account, DKIM passes. I just can’t figure out what it is about this specific user account that’s causing it to fail. And of course, it happens to be the account that I primarily want to use to send and receive mail. Without DKIM passing, I’ve noticed that Google sends my messages straight to the spam box.

    • Aha! I figured out why my single user account was failing DKIM, and I understand why:

      DKIM takes the message content and hashes it with the private key, then puts this in the email header. I was using an additional postfix configuration option called smtp_generic_maps to “rewrite” how my sender address would appear in the recipients inbox. DKIM did not like this modification and that is what was causing the DKIM check to fail on messages from this specific user. Hopefully this helps somebody else!

      Simply comment out the smtp_generic_maps parameter in your /etc/postfix/main.cf file if you’re having this problem.

      Thanks again for the wonderful guide!

  • M Aprian
    2 years ago

    After doing this part, I can send email but cannot receive email. Can you help me? 🙁

    • M Aprian
      2 years ago

      SOLVED!! I made a little mistake, sorry

      This is the best guide for mail servers (for me now), THANKS YOU

      • I’ve got same hiccup: using email client I can send but cannot receive any email. I have followed exactly the steps in this tutorial. Would you share how you solve the problem? Thanks.

        • Don’t bother. Everything is fine now. Gmail was slow. Thanks.

  • Great tutorial, worked perfectly, thanks!

  • Hello,

    In the command:
    sudo certbot –nginx –agree-tos –redirect –hsts –email your-email-address -d mail.your-domain.com

    What is the “your-email-address” I should provide ?

    Kind regards,
    Daniel

  • Hello,

    My domain is not a .com one, it is a .co.uk (let’s say test.co.uk)

    How should I replace “your-domain” in:
    “sudo nano /etc/nginx/conf.d/mail.your-domain.com.conf” ?

    Kind regards,
    Daniel

  • Daniel Orkan
    2 years ago

    Hello Xiao,

    Thank you very much for the guide, all works for me.
    Also, thank you for the support !!!

    Kind regards,
    Daniel Orkan

  • Once again. Well done. Got everything working perfectly. I couldn’t find the “buy me a beer” link, but thanks for a very thorough job. Have you done an article on virtual mailboxes yet?

  • melvin ramsey
    2 years ago

    I cannot thank you enough.
    Beautifully written article.

  • Biiiiig thank you, Xiao!!!

  • before “sudo certbot –apache –agree-tos –redirect –hsts –email your-email-address -d mail.your-domain.com”
    need to do “sudo apt-get update && sudo apt-get dist-upgrade”, cause some certbot python packages need to be upgraded. You got the error, while otbain certificates, if you dont upgrade some packages. Sorry for bad english.

  • Luke Taaffe
    2 years ago

    You absolute boss.

    I’ve rarely found a tutorial which just works.. for something so complicated and head spinning as well.
    Kudos mate, really.

  • I can’t seem to receive any external mail (ie: from gmail) – but everything else seems to be working well. Any thoughts?

    • found the solution – just needed to run this:

      sudo iptables -A INPUT -p tcp --dport 143 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
      • WRONG PORT LISTED ABOVE:

        sudo iptables -A INPUT -p tcp --dport 587 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
  • still 5 star rating! very precise and plain in language and logic writing!! Thank you very much!!!

  • Jason Reeves
    10 months ago

    Question – When opening the ports, why not just do ufw allow dovecot?

    • First, there’s no “dovecot” UFW profile.

      linuxbabe@mail:~$ sudo ufw allow dovecot
      ERROR: Could not find a profile matching 'dovecot'

      The profiles installed by the dovecot package are “Dovecot IMAP” and “Dovecot Secure IMAP”, which correspond to port 143 and port 993 respectively. They allow mail clients to fetch emails from the mail server.

      But you also need to open port 587 and 465 for mail clients to submit emails. And if you use webmail, open port 80 and 443.

      You can run the following command to display available UFW profiles.

      sudo ufw app list

      Then you can use the command below to check which port a profile allows, like

      sudo ufw app info "Dovecot IMAP"

      Output

      Profile: Dovecot IMAP
      Title: Secure mail server (IMAP)
      Description: Dovecot is a mail server whose major goals are security and
      extreme
      reliability.
      
      Port:
        143/tcp
      
  • Pablo Cordero
    10 months ago

    Hi,
    This tutorial is really good but I have a little problem with SMTP. I have configured the server in Thunderbird and the IMAP works perfect, but when I’m going to send emails, it says me something like this “Your connection has expired with the SMTP server”.
    I can send messages with the

    mail

    command perfectly, so I don’t know where is the problem. If you know any solutions, please let me know it.

    Thank you in advance!

  • Mårten Behm
    10 months ago

    Hi,
    My mail server works fine, as far as I know, after following your first three tutorials. Thank again! However, I don’t know how to make use of the letsencrypt setup. Can you provide some hint, or will you consider (maybe you already have?) writing a tutorial about this?

  • Nuno Miranda
    9 months ago

    It´s works when I try whith a gmail account, but when I try send a email to a icloud account, that´s not receiving… can you help me please?

  • Nuno Miranda
    9 months ago

    Hi, it´s me again,
    firstly thanks for your super complete tutorial, that´s help me a lot 😀

    the problem:
    I ´m in black list of icloud…..

    in mail.log i see this:
    … refused to talk to me: 550 5.7.0 Blocked…

    How can I solve this? help me :/

  • Nuno Miranda
    9 months ago

    Thanks for your support 😀 I´m gonna try that.

  • Constantinos
    9 months ago

    Superb tutorial and perfect in all aspects!
    I think I made a mistake when installing postfix and for system mail name I entered: mail.mydomain.com rather than mydomain.com and now the emails are @mail.mydomain.com rather @mydomain.com.
    Anything that can fix the issue?
    Thanks a lot

  • thanks BABE
    8 months ago

    Thanks for the guide!

    Trying to run the clean junk folders gives me an error. Any idea?

    ubuntu@mail:/home$ sudo doveadm expunge -A mailbox Trash all
    doveadm(nobody): Error: User initialization failed: Namespace ”: mkdir(/nonexistent/mail) failed: Permission denied (euid=65534(nobody) egid=65534(nogroup))
    doveadm(nobody): Error: User init failed

    ubuntu@mail:/home$ sudo doveadm user ‘*’
    nobody
    ubuntu

    • According to man doveadm-expunge, if the -A option is present, the command will be performed for all users, including the nobody user. Since the nobody user’s home directory is /nonexistent/, an error would occur because the nobody user can’t create the /nonexistent/ directory.

      You can ignore this error by redirecting the error to /dev/null. A better approach would be getting the user list from a file. You can list users with:

      sudo doveadm user '*'

      Then you can use sed to delete the line containing the word “nobody” and save the result into a text file.

       sudo doveadm user '*' | sed '/nobody/d' > userlist.txt

      Now we can use doveadm-expunge.

      sudo doveadm expunge -F userlist.txt mailbox Trash all

      Note that if you use virtual mailbox domain as described in part 3, there would be no such error, because the user list is obtained from MySQL/MariaDB database.

      • Linux BABE is AWESOME
        8 months ago

        Thank you so much for helping me understand!

  • First of all thank you for your documentation(s), it was really helpful for us!

    After all we have a little problem. We created a same virtual user like the unix user eg: user1@mydomain.com, and unix user is user1. It feels like its mixing the SMTP auth or something.
    We can get the incoming emails, but we cannot send, because it’s asking SMTP pass, which perfectly fine. (We can login into roundcube.) Other virtual users works perfectly fine, but not the matching users.

    Setup was built on your flow, so we using lemp, postfix, dovecot, postfixadmin and roundcube.

    Could you give us tip where to start debugging our problem?
    Thank you in advance!

    • I don’t think you can have a domain on Postfix that’s both a canonical domain (with Unix system account) and a virtual domain (with virtual users stored in MySQL/MariaDB database) at the same time.

      Domains listed in mydestination parameter are canonical domains. If a domain is listed in the virtual_mailbox_domains parameter, then you can not list the domain in mydestination parameter, as is described in Postfix documentation: NEVER list a virtual MAILBOX domain name as a mydestination domain!

      A virtual domain can’t have email addresses for Unix system accounts.

      • Thank you for your fast response.

        Now i understand much clearly. If mydestination is mail.mydomain.com and virtual_mailbox_domains is mydomain.com, then i can have user1@mydomain.com mailbox independently from my Unix system account which is user1.

        Could not be a problem to use the same “user” name, because the Unix system account will use the mydestination domain, right?

    • Yes. That’s correct.

      • Your help lead me to find out the problem.
        When we want to use indentical username eg: user1 for unix system account and for mailbox account, then we should define the full username (user1@mydomain.com) in the email client to incoming/outgoing username.
        Other virtual users can use simple username like presented on tutorial picture in document.
        Thanks for all✌😁

    • The username for Unix system account doesn’t have a domain name.

      The username for virtual domain user includes the domain part, as you can see by logging into MySQL/MariaDB database server and displaying the mailbox table in the postfixadmin database.

      I’m not sure if your finding is correct. I think the username field in Thunberbird is misleading.

  • Thanx for the guide!

    I can receive but I cannot send? Any clue what may cause it?

    From mail log:

    Feb  4 22:35:40 postfix/submission/smtpd[21672]: warning: database /etc/aliases.db is older than source file /etc/aliases
    Feb  4 22:35:40 postfix/submission/smtpd[21672]: fatal: in parameter smtpd_relay_restrictions or smtpd_recipient_restrictions, specify at least one working instance of: reject_unauth_destination, defer_unauth_destination, reject, defer, defer_if_permit or check_relay_domains
    Feb  4 22:35:41 postfix/master[21332]: warning: process /usr/lib/postfix/sbin/smtpd pid 21672 exit status 1
    Feb  4 22:35:41 postfix/master[21332]: warning: /usr/lib/postfix/sbin/smtpd: bad command startup -- throttling

    As per this guide I have in my master.cf file:

     -o smtpd_relay_restrictions=permit_sasl_authenticated, reject
     -o smtpd_recipient_restrictions=permit_mynetworks, permit_sasl_authenticated, reject

    So do not have idea why this fatal error is there … or maybe it is not that?

    Any help would be apreciated …

  • Hello there,

    At this stage I can received but when try to send it always says: Timeout when setting up SSL/TLS.

    The log file of the mail client shows:
    11:24:28 C: STARTTLS
    11:24:28 S: 454 4.7.0 TLS not available due to local problem
    11:24:28 Error: Unexpected return code 454 (expected 220):
    “4.7.0 TLS not available due to local problem”.
    11:24:28 Error code: 2001
    11:24:28 Failed action (0). Reset observed read/write timeouts: 8/8

    Can someone help with?

  • Hello Xiao & Thank You so much,
    – You was right, I just redone the typing and it is now working but did not found where; I am now on way to part 3.
    – Also on getting the Letsencrypt certificates you must disable the default virtual host of apache2 – “sudo a2dissite *default” – before enable your own. Otherwise it will fail every time you try to get the certificates.

    Kindest Regards.

    • Disabling the default virtual host is not a must, if you have correctly configured the mail.yourdomain.com virtual host. I have obtained numerous TLS certificates without disabling the default virtual host.

  • Hello there,
    on “Obtaining TLS Certificate with Nginx Web Server” the syntax of

    ...
    location ~ /.well-known/acme-challenge {
             allow all;
          }
    ...

    the “~” is followed by a SPACE or by the SLASH ?

  • In the file “/etc/nginx/conf.d/mail.your-domain.com.conf”,
    the line “root /var/www/mail.your-domain.com/;” move the nginx server from “Welcome to nginx!” to “403 Forbidden”,
    meaning when the line is comment with “#” the server answer with “Welcome to nginx!” and when the line is uncomment the server answer with “403 Forbidden”.

    Any clue why?

  • Hello Xiao,

    I follow this ‘IT Security Guidelines for Transport Layer Security
    (TLS)’ from NCSC-NL, guideline B2-1 to B2-4 and table 2, 4, 6 and 7 (in
    English) witch is considered here one of the best guides to cyber
    security.
    The website is :
    [https://english.ncsc.nl/publications/publications/2019/juni/01/it-security-guidelines-for-transport-layer-security-tls]

    The test tool is : “internet.nl”

    About my installation they say on Ciphers (Algorithm selections) this:

    •••••••••••••••••••••••••
    Technical details:
    Mail server (MX): mail.digitalblueprint.eu.
    First found affected cipher: DHE-RSA-SEED-SHA
    Status: phase out
    •••••••••••••••••••••••••
    At least one of your mail servers supports one or more ciphers that have
    a phase out status, because they are known to be fragile and are at risk
    of becoming insufficiently secure.

    Is there any way to unused phased out Ciphers?


    Kindest Regards,
    Alex

    • You can add the following lines in Postfix main configuration file to improve the security of TLS connection.

      #Enforce high grade TLS ciphers
      smtpd_tls_ciphers = high
      smtpd_tls_mandatory_ciphers = high
      
      #Exclude non-secure ciphers
      smtpd_tls_mandatory_exclude_ciphers = MD5, DES, ADH, RC4, PSD, SRP, 3DES, eNULL, aNULL
      smtpd_tls_exclude_ciphers = MD5, DES, ADH, RC4, PSD, SRP, 3DES, eNULL, aNULL
      smtp_tls_mandatory_exclude_ciphers = MD5, DES, ADH, RC4, PSD, SRP, 3DES, eNULL, aNULL
      smtp_tls_exclude_ciphers = MD5, DES, ADH, RC4, PSD, SRP, 3DES, eNULL, aNULL
      
      #Disable client-initiated renegotiation to prevent DoS attacks inside a TLS connection
      tls_ssl_options = 0x40000000
      
      #Enable server cipher-suite preferences
      tls_preempt_cipherlist = yes
      

      However, don’t be obsessed with TLS for SMTP and IMAP servers. If you are too strict about TLS, then there will be SMTP clients that can’t establish TLS connection with your SMTP server.

  • Dejan Zivanov
    7 months ago

    Hi i am having currently problem with the setting up my account via Thunderbird for start. I went three times over all three tutorials but something is always not working, i think i am maybe wonky with my fingers or whatever. But here we go, third time is the charm. So, at the moment i am at this stage(2nd).

    And when i am trying to connect via Thunderbird, what password should i use?
    Because we never created that during first 2 tutorials.

    Should i use password that i am using to connect via terminal?

    • The first two parts use local Unix accounts as email addresses. For example, if you have a user called dejan on your Ubuntu server, then you have an email address: dejan@yourdomain.com, and the password for the email address is the same password for the dejan user.

      • Dejan Zivanov
        7 months ago

        Thank you, i managed to login via THunderbird, but at the moment i am getting this error(in var/logs) dovecot: imap(contact): Error: Failed to autocreate mailbox Trash: Permission denied

        Not sure what could be cause of this problem

  • please note that (at this date: 28/03/2020) in my machine: ubuntu 18.04.3 , the file: /etc/dovecot/conf.d/10-master.conf had the ports commented out, this resulted in the ports being “closed” when scanned from the outside
    Other tan that, great job, I cant say wether all of this is needed to set it up in a “simple” way but anyway thanks 🙂

  • Quang Mai
    5 months ago

    Hi Xiao,

    I have another issues with the Thunderbird setup account:
    I checked all the Q&A above in the thread and I understand that the user@mydomain.com as the UNIX root and password. Do you have any solutions? How do I create a second: user2@mydomain.com to check it? Thanks so much.

    • To create another email address, simply create another Unix user account on your Ubuntu server.

      sudo adduser user2

      Part 3 will show you how to create virtual users.

  • Hello,

    Loving my setup… Thanks – I have followed all the way through (all 8ish parts).
    I have run into one Challenge post setup, and this is confusing me.
    Firstly… worth noting – Your setup is working!!!
    It is working for all devices apart from an OLD Samsung Tab 2 failed the setup.
    I have put this current challenge on this page as I think it could be the TLS SSL min protocols being part of the problem. But I don’t really want to tinker as I don’t know why you suggested these protocols. – Any suggestions as to what could be causing 1 old device to not work.
    The device also doesn’t allow STARTTLS , so tried every option and none worked.

    Also – feature request – PUSH messages, I would like to use this account for messages but the 15 mins or so i have to wait for IOS messages feels like an eternity . I have been searching and it appears you have to pay for Apple notification service? Feels bonkers!

  • neutek-narco
    5 months ago

    Thank you!

    I had to use this command to get past 404 errors with certbot

    certbot certonly –agree-tos –expand –authenticator webroot –installer apache -d mail.domain.org –webroot-path /var/www/mail.domain.org/

  • Andrés Gutiérrez
    5 months ago

    ssl_protocols = !SSLv3 !TLSv1 !TLSv1.1 (Dovecot ver. 2. 3. x)

    Is no longer needed.

  • Ken Wright
    5 months ago

    Having a problem here. I’ve run the Postfix instructions in Part 2, but when I check systemctl status postfix it says postfix is “active (exited). Does this mean Postfix isn’t running? What have I done wrong?

    • This is normal, because the Postfix systemd service is a oneshot service. Postfix will run the master process after the main Postfix exits. If you run the following command, you can verify if Postfix master process if running.

      sudo netstat -lnpt | grep master

      Output:

      tcp        0      0 0.0.0.0:587             0.0.0.0:*               LISTEN      1200577/master      
      tcp        0      0 0.0.0.0:465             0.0.0.0:*               LISTEN      1200577/master      
      tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      1200577/master      
      tcp6       0      0 :::587                  :::*                    LISTEN      1200577/master      
      tcp6       0      0 :::465                  :::*                    LISTEN      1200577/master      
      tcp6       0      0 :::25                   :::*                    LISTEN      1200577/master    
      

      As you can see, the Postfix master process is listening on port 587, 465 and 25 on my mail server.

      The dovecot systemd service is a simple service, so you will see “active(running)” instead of “active(exited)”.

  • Ken Wright
    5 months ago

    That’s not what I get. I don’t see 587 or 465 listed when I run the above command. Any ideas?

  • Ken Wright
    5 months ago

    Found the problem! I had missed an underline character in /etc/postfix/main.cf. Once I fixed that and reloaded Postfix, everything fell into place.

  • Hello Xiao,

    mail client connects, i can send mail. have recieved mail waiting to be collected by mail client
    mail.log shows client connecting:

    Apr 29 19:17:28 mail postfix/lmtp[4192]: 1EA5621894: to=, relay=none, delay=2251, delays=2251/0.04/0.02/0, dsn=4.4.1, status=deferred (connect to mail.XXXX.XX[private/dovecot-lmtp]: No such file or directory)
    

    Not sure which side to start looking to solve this, do u have an idea?

    • Disabled the steps done in lmtp setup for now, imap works.

    • LMTP is required if your want to follow part 3 of this tutorial series.

      • I understand that, but my client doesnt seem to be able to collect my mail if its activated, ihave no idea why atm… what file/directory is it missing? and earlier i added lmtp behind imap as set protocols. but imap doesnt work if lmtp is there? or is there another issue?

  • I have already postfix installed as a sendonly SMTP server using your other guide. I want to be able to also send from desktop client. Do I need to install dovecot to be able to communicate with Postfix? If so, are there other steps I can omit from this guide when I don’t need to receive email?

  • Hmm really? So my wordpress server is sending out emails. Sometimes I need to write a custom email.
    Another server is taking care of incoming mail.
    Do you mean that you send only postfix server guide shouldn’t be combined with an external mail server for incoming and other email?
    I can also send mail from the other server, but not in this case (my colleague is in China, where gmail is blocked so can’t send out email).
    Thanks.

    • I mean if you send an email from your own domain, but the reply email goes to a free third-party email service like gmail, that will trigger some spam filters. Why not receive reply emails on your own domain?

      • I do receive emails to my own domains. GSuite (gmail) is setup for incoming mail to mydomain.com. The wordpress server is not connected to Gsuite and sending with Postfix. I though from your-send only Postfix guide that this was a ok setup?

    • Ok. I understand now. Simply follow the instructions in this article and you will be able to use desktop email client. Note that inet_interfaces should be set to all in the /etc/postfix/main.cf file.

  • Thanks, so you mean I do need dovecot even when I will not receive mail?

    • Mozilla Thunderbird, and also other mail clients I think, will not allow you to log into your mail server or send emails if there’s no IMAP/POP3 server running.

  • Ok, I see. I thought the separate settings in thunderbird etc for smtp server was connecting directly to postfix, but I guess that’s also dovecot than.

  • Victor Kulibaba
    5 months ago

    Hi Xiao, thank you for the awesome guide!
    I keep to fail at the last step (configuring Thunderbird). It always shows error box that IMAP server doesn’t allow choosen authentication method.
    I checked nmap for srv.kulibaba.site and it seems that all necessary ports are open.
    Also dovecot is running fine:

    ● dovecot.service - Dovecot IMAP/POP3 email server
       Loaded: loaded (/lib/systemd/system/dovecot.service; enabled; vendor preset: enabled)
       Active: active (running) since Sun 2020-05-10 21:01:19 MSK; 1h 7min ago
         Docs: man:dovecot(1)
               http://wiki2.dovecot.org/
      Process: 15947 ExecStop=/usr/bin/doveadm stop (code=exited, status=0/SUCCESS)
      Process: 16148 ExecReload=/usr/bin/doveadm reload (code=exited, status=0/SUCCESS)
      Process: 15986 ExecStart=/usr/sbin/dovecot (code=exited, status=0/SUCCESS)
     Main PID: 15990 (dovecot)
       CGroup: /system.slice/dovecot.service
               ├─15990 /usr/sbin/dovecot
               ├─15993 dovecot/anvil
               └─16151 dovecot/log
    
    May 10 21:41:47 srv.kulibaba.site dovecot[16151]: imap-login: Disconnected (no auth attempts in 0 s
    ecs): user=, rip=185.48.37.80, lip=194.58.119.56, TLS: SSL_read() failed: error:14094412:SSL rout
    ines:ssl3_read_bytes:sslv3 alert bad certificate: SSL alert number 42, session=
    

    In the log part you can see the error I get.
    When I created let’s encrypt certificate for srv.kulibaba.site I also added –must-staple option, that’s probably the only thing I did “against” your guide…
    I also tried to tweak Thunderbird changing general.useragent.compatMode.firefox to True, though it didn’t help. Neither choosing oAuth2 as auth method helped. My next concern is ssl = required in 10-ssl.conf, but at this point I decided to refer to the source, making this comment.
    Btw, initially if my hostname and MX record is srv.kulibaba.site, was it right to create virtual nginx host and issue certificate using this name instead of “mail.kulibaba.site”?

    • Victor Kulibaba
      5 months ago

      Seems like I managed to resolve the issue by setting:
      security.ssl.enable_ocsp_must_staple = false
      in Thunderbird config editor

    • Postfix and Dovecot don’t support OCSP stapling. If you add --must-staple to your TLS certificate, then mail clients (Thunderbird) would refuse to connect. I didn’t test it, but other SMTP servers are probably not able to establish secure TLS connection with your Postfix SMTP server.

      So I recommend obtaining a new TLS certificate for your hostname (srv.kulibaba.site) without using --must-staple.

      • On ubuntu 20.04LTS “ssl_min_protocol = TLSv1.3” is not supported and we need to upgrade to at least dovecot 2.8

        Can you help with ?

        • The latest stable version of Dovecot is 2.3.

          Don’t be obsessed with using the latest cutting-edge TLS settings. That’s why you get TLS errors in your mail log. TLSv1.2 is secure enough.

  • Victor Kulibaba
    4 months ago

    Hi Xiao, at the beginning of the guide you wrote: “You need to have an Nginx virtual host for mail.your-domain.com before obtaining Let’s Encrypt TLS certificate”.

    This is probably not true, I just need the certificate and see no reason in creating root folder and granting access to www-data. So I used certbot “certonly” option and configured nginx to make MX url forbidden (return 403). It seems to work fine. Do you see any problem with that?

    • Creating a virtual host is not a must if you have a default Nginx virtual host. There’s no problem with your method. However, you need to create a dedicated Nginx virtual host if you want to install Roundcube webmail later.

      • On Obtaining TLS Certificate with Nginx Web Server for ubuntu 20.04LTS I get the following error:

        “AttributeError: module ‘acme.challenges’ has no attribute ‘TLSSNI01′”

        Any clue on how to resolve this?

        • If you see the following error while trying to obtain TLS certificate on Ubuntu 20.04

          module 'acme.challenges' has no attribute 'TLSSNI01'

          You need to edit a config file.

          sudo nano /usr/lib/python3/dist-packages/certbot_nginx/configurator.py

          Change

          return [challenges.HTTP01, challenges.TLSSNI01]

          to:

          return [challenges.HTTP01]

          Save and close the file. Then run the certbot command again to obtain TLS certificate.

  • Laurentiu
    4 months ago

    Hello Xiao,

    thank you for your very good tutorial. I successfully installed an email server using it. All good, but one point.

    We have an ERP application which should send emails, but I cannot connect it to my email server. Not sure if I a missing some options of if I am inputing somethin wrong.

    So I have:
    outgoing mail server: mail.mydomain.com
    port: 25
    encryption: TLS

    error: could not connect to SMTP host.
    I tested with SMTP authentication (just took one created email address, not sure if I need another SMTP account..), I also tried without authentication.

    Can you please give some insight?

    Thank you!

    • You should use port 587.

      • Laurentiu
        4 months ago

        Tahnk you.
        Using port 587 I am a step closer. Same error if trying to connect to mail.domain.com but working if connecting to internal server IP.
        Tested without SMTP auth (this is correct)?
        New error on test email:

        Mailer Error: Language string failed to load: tls The following From address failed: test@domain.com Called Mail() without being connected

        Can you please help with this error?

        Thank you!

    • You should enable SMTP auth (enter an email address and password) on port 587.

  • really very nice and awesome tut! thanks for ur work

    im trying to install mailserver for only local use, i have my own local dns server (bind9) and have mx record and stuff for my mail server, obv i cant use Let’s Encrypt, so im using openssl instead, followed to this part, i think everything’s fine

    i can login using thunderbird in my laptop fine, it auto detect my settings, i try to send test email to myself (or another local account), i see the mail in sent folders but i receive nothing in inbox.

    i see this in the /var/log/mail.log

    May 23 12:58:34 tsun postfix/submission/smtpd[2723]: connect from unknown[192.168.7.17]
    May 23 12:58:34 tsun postfix/submission/smtpd[2723]: Anonymous TLS connection established from unknown[192.168.7.17]: TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
    May 23 12:58:34 tsun postfix/submission/smtpd[2723]: CC429802AE: client=unknown[192.168.7.17], sasl_method=PLAIN, sasl_username=veelst
    May 23 12:58:34 tsun postfix/cleanup[2728]: CC429802AE: message-id=
    May 23 12:58:34 tsun postfix/qmgr[2556]: CC429802AE: from=, size=576, nrcpt=1 (queue active)
    May 23 12:58:34 tsun postfix/submission/smtpd[2723]: disconnect from unknown[192.168.7.17] ehlo=2 starttls=1 auth=1 mail=1 rcpt=1 data=1 quit=1 commands=8
    May 23 12:58:34 tsun postfix/smtp[2729]: CC429802AE: to=, relay=none, delay=0.07, delays=0.06/0.01/0/0, dsn=5.4.6, status=bounced (mail for tsun.net loops back to myself)
    May 23 12:58:34 tsun postfix/cleanup[2728]: EBED4802C6: message-id=
    May 23 12:58:35 tsun postfix/bounce[2730]: CC429802AE: sender non-delivery notification: EBED4802C6
    May 23 12:58:35 tsun postfix/qmgr[2556]: EBED4802C6: from=, size=2417, nrcpt=1 (queue active)
    May 23 12:58:35 tsun postfix/qmgr[2556]: CC429802AE: removed
    May 23 12:58:35 tsun dovecot: imap(veelst): Logged out in=544 out=708 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
    May 23 12:58:35 tsun postfix/smtp[2729]: EBED4802C6: to=, relay=none, delay=0.04, delays=0.04/0/0/0, dsn=5.4.6, status=bounced (mail for tsun.net loops back to myself)
    May 23 12:58:35 tsun postfix/qmgr[2556]: EBED4802C6: removed

    i dont know where im going wrong, help is much appreciated!
    thanks!

    • for some reasons i see the reply is posted “4 seconds ago” and it been days lol
      anyway, solved my problem thanks!

  • Thanks for this tutorial!

    Getting the following:

    Jun  5 22:46:03 mail postfix/lmtp[2256]: 68E00FC1A5: to=, relay=mail.example.com[private/dovecot-lmtp], delay=509, delays=509/0.03/0.03/0.02, dsn=5.1.1, status=bounced (host mail.example.com[private/dovecot-lmtp] said: 550 5.1.1  User doesn't exist: user1@example.com (in reply to RCPT TO command))
    

    Of course, user1@example.com isn’t the real address.

    I created user1 with:

    sudo adduser user1

    I can sign in with IMAP, but can’t send to it. Thoughts? Thanks!

    • What’s the output of this command:

      postconf mydestination
      • mydestination = $myhostname, example.com, mail.example.com, localhost.example.com, localhost

        Thanks!

        • SeanP
          4 months ago

          I disabled the LMTP stuff and now it’s working okay. I don’t need virtual mailboxes so I’m good. Thanks so much!

  • Mysterion
    4 months ago

    Hi, thanks for the great tutorial!

    What if Postfix and dovecot are running on separate servers like smtp.example.com and imap.example.com? How to configure LMTP?

    • Edit the Dovecot 10-master.conf file.

      sudo nano /etc/dovecot/conf.d/10-master.conf

      When Postfix and Dovecot are running on separte servers, you need to make LMTP service listen on TCP socket. Change the lmtp service definition to the following.

      service lmtp {
      
       unix_listener /var/spool/postfix/private/dovecot-lmtp {
         mode = 0600
         user = postfix
         group = postfix
        }
      
        inet_listener lmtp {
          address = 10.10.10.2
          port = 2424
        }
      
      }
      

      LMTP should be used in a local LAN and not be visible to the Internet, so you should use a private IP address for the inet_listener. Replace 10.10.10.2 with your own private IP address. If your SMTP server and IMAP server are not in the same LAN, you can use wireguard to create a virtual private network.

      Save and close the file. Then restart Dovecot.

      sudo systemctl restart dovecot

      Next, edit the Postfix main configuration file on the other server.

      sudo nano /etc/postfix/main.cf

      Add the following lines at the end of the file. The first line tells Postfix to deliver emails to local message store via the dovecot LMTP server listening on 10.10.10.2:2424. The second line disables SMTPUTF8 in Postfix, because Dovecot-LMTP doesn’t support this email extension.

      mailbox_transport = lmtp:inet:10.10.10.2:2424
      smtputf8_enable = no
      

      Save and close the file. restart Postfix.

      sudo systemctl restart postfix
  • outbox/drafts etc not creating automatically:

    When i set the 15-mailboxes.conf to create boxes automatically, then create a user with “sudo adduser user1” and then add it to thunder bird thunderbird only contains the inbox and nothing else (which confuses it when it tries to save sent mails to outbox etc)

    “`

    mailbox Junk {
    auto = create
    special_use = \Junk
    }
    mailbox Trash {
    auto = create
    special_use = \Trash
    }

    # For \Sent mailboxes there are two widely used names. We’ll mark both of
    # them as \Sent. User typically deletes one of them if duplicates are created.
    mailbox Sent {
    auto = create
    special_use = \Sent
    }
    mailbox “Sent Messages” {
    special_use = \Sent
    }
    “`

    • The “Sent” folder will be automatically created when you send the first email. The “Trash” folder will be automatically created when you delete an email, etc.

  • Huge thanks for creating and maintaining this guide!

    Everything is working happily for me… except the Microsoft Mail App (on Windows 10) which, no mater what I’ve tried, proclaims “Untrusted certificate”.

    The cert is configured in /etc/dovecot/conf.d/10-ssl.conf
    Another client I’ve tried (GMail on Android) doesn’t complain about the cert.
    I’ve configured the MS Mail App to use mail. names for the incoming and outgoing servers and used the suggested ports of 143 and 587 (which default to imap.:993 for incoming and smtpauths.:25 for outgoing)
    I almost wonder if despite the settings it’s still expecting to see imap. and smtpauths. listed in the cert or some other stupidity… it really gives me no detailed error information to go on.
    I’ve sworn at it repeatedly and cursed windows 10 many times

    I can ignore the “untrusted certificate” warning and everything appears happy – of course then once the cert gets renewed the windows mail app just silently stops syncing because the force-accepted cert no longer matches the retrieved cert and i have to remove the account(s), re-add them, and ignore the untrusted cert issue again because MS.

    At this point I don’t think the problem is on the linux postfix/dovecot side, HOWEVER, I did experience my gmail client silently stop syncing too – until today when i was fiddling with my linux configs again when the gmail app suddenly started syncing my mail again.

    If I can’t get this figured out I guess I’ll have to setup a daily cron to flick an email at me as a canary and go through the remove/re-add account process when the daily mails stop due to the cert being refreshed… I’d really like to solve this problem correctly though and have confidence that I’m not missing important mails.

    Thanks again! Sorry for getting long winded here.

  • Thank you so very much!

    This is by far the most helpful tutorial about anything that I have ever read, for so many reasons.

    Cheers!

  • Akarshit Waal
    3 months ago

    Hey! Great article. I have one doubt. I have a client send me a mail on port 25(which I cannot change). After following the first part, the client was able to send the mail on 25 and I was able to receive it.
    After the 2nd part postfix was not listening to port 25.
    I found out that `smtp inet n – y – 1 postscreen` line was commented in master.cf. I uncommented it and now I see it listening to port 25, but when the client tried to send a mail, he get’s no response and the request is just pending. Any idea what could be missing?

  • Where does postfix (or dovecot) even store these emails please?

    • If you are using virtual mailbox (PostfixAdmin), the emails are stored in /var/vmail/yourdomain.com/username.
      If you are not using virtual mailbox, the emails are stored under ~/Maildir (The Maildir subdirectory under each user’s home directory.)

      • Much appreciated

        • ivan006
          3 months ago

          im not using virtual mailbox. Is it “/root/Maildir/new”? “/root/Maildir” has no other loose files and its other subdirectories ae empty. Anyway if it is “/root/Maildir/new” I see there are files in there but nothing after the 13 (this month) but i have sent many emails why is this? how is this even working?

        • ivan006
          3 months ago

          oh i see its in
          /home/plefort/Maildir

    • One more question. When i add my custom email account to gmail it doesnt save my sent emails to the sent folder. any thoughts?

      • is it because its using pop conventions, and so doesnt care about server storage, and so wont save anything to the server?

    • I’m not sure what you mean by “add my custom email account to gmail”.

  • Insignia
    3 months ago

    Hello,

    First, thank you for the detailed tutorial on setting up an email server with Ubuntu!
    I’ve also followed the RoundCube tutorial (And the Postfix tutorial)from you and setup everything properly, but there seems to be an obstacle that prevents me from using Roundcube.

    Logging in to Roundcube works perfectly fine, but sending and receiving emails cannot be done.
    When using my email to test the server, I get a “Mail Undeliverable” message with the following error:

    :host
    mail.domain.com [private/dovecot-lmtp] said: 550 5.1.1
     user does not exist:
    administrator@domain.com (in Reply to RCPT TO command)

    So the mail server cannot receive email.

    Sending email using the Roundcube does nothing. After I compose a test email and click send, Roundcube would keep loading with no progress until I get an error that says “Request timed out”

    What can I do to resolve this? Any leads would be appreciated, thank you!

    • Insignia
      3 months ago

      Looks like some information was omitted for some reason, here is the actual error message I get from trying to send an email to my mail server:

      (administrator@domain.com):host
      mail.domain.com [private/dovecot-lmtp] said: 550 5.1.1
      (administrator@domain.com) user does not exist:
      administrator@domain.com (in Reply to RCPT TO command)
  • Insignia
    3 months ago

    Okay so now I can receive emails in the server. There is a minor change that I need to do in

    etc/dovecot/conf.d/10-auth.conf

    I had to modify this line to include %Ln

    auth_username_format = %Ln

    This fixed the issue of not being able to receive emails in the mail server. But the problem of sending emails still persists. The Roundcube just loads indefinitely until the request timed out.

    • If you encounter errors with Roundcube, you can check the error logs at /var/log/apache2/roundcube_error.log (if you are using Apache), or /var/log/nginx/roundcube.error (if you are using Nginx.)

      • Insignia
        3 months ago

        Thank you for this guide! It’s been very thorough and helpful

    • Insignia
      3 months ago

      Nevermind, the issue has been resolved. I checked /var/log/mail.log and found out where the issue is. There was a typo (my bad lol) in master.cf file. After I fixed that one typo, and restarted the service, Roundcube can send and receive emails without problem.

  • Hironori
    3 months ago

    Hi, Xiao. Thank you for helpful tutorials so much!! And I can’t send & recieve mail until this stage. mail.log says
    mail postfix/lmtp[3305]:: to=, relay=mail.example.com[private/dovecot-lmtp], delay=0.14, delays=0.09/0.01/0.02/0.02, dsn=5.1.1, status=bounced (host mail.example.com[private/dovecot-lmtp] said: 550 5.1.1 User doesn’t exist: user1@example.com (in reply to RCPT TO command))
    Any ideas? thanks

    • Perhaps your email address is in lower case, but you used upper case when you send the email. You can edit the /etc/dovecot/conf.d/10-auth.conf file and change the auth_username_format to

      auth_username_format = %Ln

      So dovecot would lowercase the username. Restart Dovecot.

      sudo systemctl restart dovecot
      • Hello there,

        After installing Dovecot on ubuntu 20.04LTS i found out that dovecot 2.3.7.2 does not work with SSL1.3. So I need to update Dovecot to at least the version 2.3.8 or to the stable version 2.4

        Can you help with?

        • The latest stable version of Dovecot is 2.3.

          Don’t be obsessed with using the latest cutting-edge TLS settings. That’s why you get TLS errors in your mail log. TLSv1.2 is secure enough.

  • I concur this is an AMAZING write-up, thank you. I have several gsuite accounts and am trying to migrate one over to my local MX. Like a few others, I’ve completed the setup, triple checked your instructions, confirmed that there are no postfix or dovecot errors, yet can only send messages, but not receive any. Now, if I send a message from the domain I migrated, me@acme.com to me@acme.com it appears in my inbox. If I send from me@acme.com to me@gmail.com – it also WORKS, but if I send from me@gmail.com to me@acme.com the message never arrives in my Inbox. (18.04, Dovecot v. 2.3.10.1)
    Thank you.

    • If there are no errors in mail log (/var/log/mail.log) after sending emails from gmail to your domain address. It could be:

      1.) Your MX record is wrong, or the MX hostname doesn’t have an IP address.

      2.) Port 25 (inbound) is closed.

      • Awesome. Port 25 was the issue; I’m 100%. I appreciate the article and the prompt response.

  • Hello there,

    my mail log have a lot of this

    SSL_accept error from st43p00im-ztfb10063301.me.com[17.58.63.179]: -1
    Jul 7 16:44:01 www postfix/smtpd[66273]: warning: TLS library problem: error:14209102:SSL routines:tls_early_post_process_client_hello:unsupported protocol:../ssl/statem/statem_srvr.c:1685

    What can be this? On their side or on my side?

    Thank You

  • One other thing, I saw this message in mail.log:
    ‘mail dovecot: config: Warning: please set ssl_dh= /etc/dovecot/dh.pem’
    After executing the suggested command, I didn’t see that message again…
    HTH and thanks for your work on this how-to 🙂

  • Last suggestion: I always found it complicated and error-prone to get a Letsencrypt certificate via the method you recommend (which is the method commonly adopted in how-to’s on the Web). Instead, I prefer to stop the Web server and use the following command, which works without hassle every time:

    certbot certonly –standalone –preferred-challenges http -d example.com -d www.example.com

    (obviously, you have to replace ‘example.com’ with your own domain.) Then I respond to the prompts for a mail address and permission to be contacted by EFF and restart the Web server. I prefer to do certificate renewals in the same way…

    • You have to stop your web server again when you renew TLS certificate. (every 90 days)

      If it’s not working, you have done something wrong. If you paste the error message when obtaining TLS certificate, perhaps I can help.

      • I have my certificates, and they’re working fine… I think you missed the point of what I was saying… 😉
        Personally, I find that ‘certbot certonly –standalone’ with the Web server temporarily shut down is a lot less hassle than being obliged to set up the vhosts first and satisfy all the constraints of using the nginx/apache2 plugins…

  • Priyanka Prakash
    2 months ago
     
    55A0647057     3331 Sun Jul 12 09:24:46  priyankaprakashchand@gmail.com
           (connect to mail.descmail.me[private/dovecot-lmtp]: Connection refused)
                                             ubuntu@descmail.me
     

    I am not sure what the issue is but the postfix server receives my emails and they get stuck in the deffered ques because lmtp connection is being refused. The above is the output of “mailq”. Please help!

  • I have problem on this step, when I type:

    sudo netstat -lnpt | grep dovecot

    No one appeared or responded. And with this command:

    systemctl status dovecot
    root@mail:~# systemctl status dovecot
    ● dovecot.service - Dovecot IMAP/POP3 email server
       Loaded: loaded (/lib/systemd/system/dovecot.service; enabled; vendor preset: enabled)
       Active: failed (Result: exit-code) since Tue 2020-07-14 07:54:41 UTC; 8s ago
         Docs: man:dovecot(1)
               http://wiki2.dovecot.org/
      Process: 1246 ExecStart=/usr/sbin/dovecot -F (code=exited, status=89)
     Main PID: 1246 (code=exited, status=89)
    
    Jul 14 07:54:41 mail.rsudpbari.com systemd[1]: Started Dovecot IMAP/POP3 email server.
    Jul 14 07:54:41 mail.rsudpbari.com dovecot[1246]: doveconf: Fatal: Error in configuration file /eJul 14 07:54:41 mail.rsudpbari.com systemd[1]: dovecot.service: Main process exited, code=exited,Jul 14 07:54:41 mail.rsudpbari.com systemd[1]: dovecot.service: Failed with result 'exit-code'.
    

    How to fix it? Thank you!

    • Sorry, now everthing is working.

      root@mail:~# sudo systemctl restart dovecot
      root@mail:~# systemctl status dovecot
      ● dovecot.service - Dovecot IMAP/POP3 email server
         Loaded: loaded (/lib/systemd/system/dovecot.service; enabled; vendor preset: enabled)
         Active: active (running) since Tue 2020-07-14 08:29:29 UTC; 1s ago
           Docs: man:dovecot(1)
                 http://wiki2.dovecot.org/
       Main PID: 1955 (dovecot)
          Tasks: 4 (limit: 2317)
         CGroup: /system.slice/dovecot.service
                 ├─1955 /usr/sbin/dovecot -F
                 ├─1964 dovecot/anvil
                 ├─1965 dovecot/log
                 └─1971 dovecot/config
      
      Jul 14 08:29:29 mail.rsudpbari.com systemd[1]: Started Dovecot IMAP/POP3 email server.
      Jul 14 08:29:29 mail.rsudpbari.com dovecot[1955]: master: Dovecot v2.2.33.2 (d6601f4ec) starting up for imap, pop3, imap, pop3 (core dumps disabled)
      

      Thanks Xiao Guoan!

  • after running sudo netstat -lntp | dovecot I am getting the following error message:
    doveconf: Fatal: Error in configuration file /etc/dovecot/conf.d/10-ssl.conf line 14: ssl_cert: Can’t open file /etc/letsencrypt/live/mail.lobap.ca/fullchain.pem: Permission denied
    Any suggestion on how to fix it, please.

  • Hi, hope to save me. Everything is perfect until this command UbuntuServer 20.04.
    “sudo add-apt-repository ppa:certbot/certbot”

    E: The repository ‘http://ppa.launchpad.net/certbot/certbot/ubuntu focal Release’ does not have a Release file.
    N: Updating from such a repository can’t be done securely, and is therefore disabled by default.
    N: See apt-secure(8) manpage for repository creation and user configuration details.

    I can´t install TLS Certificate. the port 443 does not open “attach picture”
    I opened the ports by firewall UFW and I call my isp and all port are open. can you help me?

    • Certbot doesn’t have a PPA for Ubuntu 20.04. Remove it with:

      sudo add-apt-repository --remove ppa:certbot/certbot

      Install certbot from the default software repository.

      sudo apt update
      sudo apt install certbot
  • Alex Xia
    1 month ago

    Hello Guo an,
    When I send an email to my gmail account, there is a red lock on gmail which means that my email is not encrypted. However, my TLS letsencrypt connection is working so I don’t know what the problem is. How do I get rid of the red lock?

    • Maybe you forgot to add the following lines in /etc/postfix/main.cf file?

      smtp_tls_security_level = may
      smtp_tls_loglevel = 1
      smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
      
      • Alex Xia
        1 month ago

        Found the problem!
        It turns out that my postfix had enabled a PIX workaround “disable esmtp” which for some reason downgraded the connection to a HELO connection to Google.
        I had the following line in my mail.log file:

         enabling PIX workarounds: disable_esmtp delay_dotcrlf for gmail-smtp-in.l.google.com 

        This problem was fixed when I added the following line in my main.cf file:

         smtp_pix_workarounds = delay_dotcrlf 
  • Sherratt
    1 month ago

    Absolutely great guide. Life-saver!

  • IMRON HS
    1 month ago

    When I try this step:

    sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email you@example.com -d mail.your-domain.com
    

    I got error message like attach file, can you help me Xiao?

  • Robert Herzog
    4 weeks ago

    My Ubuntu 20.04 did not allow incoming traffic, while I explicitly have given ufw allow 25
    In postfix main.cf file, I changed inet_interfaces from 127.0.0.1 to 0.0.0.0
    If I understand well, the postfix installation that preexisted on my rented server was looking only at localserver for email. Probably kind of a countermeasure to prevent newly installed servers from accepting-relaying smap if postfix is not properly configured…
    Robert

  • Herzog Albert
    4 weeks ago

    Thanks ! This is indeed what I tried and it cured the issue.
    Robert

  • I keep getting the following error when trying to obtain a TLS certificate. I definitely have an A record on my godaddy domain page that leads to the server IP address. Is there anything else that could be causing this?

       Domain: mail.domainname.online
       Type:   None
       Detail: DNS problem: NXDOMAIN looking up A for
       mail.josephngechu.online - check that a DNS record exists for this
       domain
    
    • I can’t find the A record for mail.josephngechu.online. https://dnsmap.io/#A/mail.josephngechu.online

    • Hector Garcia
      2 weeks ago

      Hello,

      Great guide. I’m getting this error when installing the certbot certificate:

       - The following errors were reported by the server:
      
         Domain: mail.lunitacrafts.com
         Type:   None
         Detail: DNS problem: NXDOMAIN looking up A for
         mail.lunitacrafts.com - check that a DNS record exists for this
         domain
       - 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.
      

      It didn’t show up on dnsmap.io so i contacted namecheap and they told me (for the A and AAAA records) to get rid of the domain in the host field so to only have it as “mail”. It showed up on dnsmap.io but then i got this error:

       - The following errors were reported by the server:
      
         Domain: mail.lunitacrafts.com
         Type:   unauthorized
         Detail: Invalid response from
         http://mail.lunitacrafts.com/.well-known/acme-challenge/IRyYyYc_boEZJ7CPXEdRJQPHB7LoipSFbqzO30jt_dQ
         [2607:5501:3000:1141::2]: "\n\n404 Not
         Found\n\n

      Not Found

      \n<p" 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.

      Your help fixing this would be much appreciated.

      • Can’t find your A or AAAA record on dnsmap.io.

        • Hector Garcia
          2 weeks ago

          Sorry i left it with the broken records to see the error message. It now gives me this error message when i run the certbot certificate. I checked the IPv4 and v6 I entered and they’re correct.

          Domain: mail.lunitacrafts.com
          Type: unauthorized
          Detail: Invalid response from
          http://mail.lunitacrafts.com/.well-known/acme-challenge/MNUHdMy9MMeKL8fe5KOEecoCDaLkUFDJMV_lESlhckc
          [2607:5501:3000:1141::2]: “\n\n404 Not<br /> Found\n\n

          Not Found

          \n<p"

          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.

      • It seems a firewall is blocking http/https requests to your mail server.

        You need to open the following TCP ports on your mail server.

        25,80,443,587,465,143,993
  • Robert J
    3 weeks ago

    Hello. I am having issues with getting incoming mail working. I keep getting the error below when a mail server tries to connect to me:

    Sep  2 21:03:45 lucy postfix/smtpd[308599]: warning: SASL: Connect to /var/spool/postfix/private/auth failed: No such file or directory
    Sep  2 21:03:45 lucy postfix/smtpd[308599]: fatal: no SASL authentication mechanisms

    The file definitely exists with what look like the correct permissions:

    root@lucy:/etc/dovecot# ls -la /var/spool/postfix/private/auth
    srw-rw---- 1 postfix postfix 0 Sep  2 21:03 /var/spool/postfix/private/auth

    And here is my config excerpt from dovecot’s 10-master.conf:

    service auth {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    # Postfix smtp-auth                                                                                                                                                                                                                                                                                           unix_listener /var/spool/postfix/private/auth {
        mode = 0660                                                                                                                                                                                                                                                                                                   user = postfix                                                                                                                                                                                                                                                                                                group = postfix                                                                                                                                                                                                                                                                                             }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     } 

    I am at a loss to what the problem could be. I am using Ubuntu 20.04 LTS.

  • Besides configuring dovecot’s mailbox, postfix also needs to be configured; which is missing in this tutorial:

    sudo postconf -e “home_mailbox = Maildir/”

    • Unless you didn’t configure LMTP as told in this article.

      The home_mailbox parameter is used by Postifx’s local delivery agent. After configuring LMTP, Postfix will not use its own local delivery agent, but pass incoming emails to Dovecot via LMTP protocol, which is effected by the following setting. Postfix doesn’t care which mailbox format you are going to use.

      mailbox_transport = lmtp:unix:private/dovecot-lmtp
      • Yes, thanks for the hint. I did miss the service lmtp configuration part. Thus, I ultimately ran into another issue, I just was able to solve. (dovecot-lmtp: No such file or directory) Thanks for the lesson! Your tutorial is great and our Email-SRV is up and running flawlessly. (A bit slow, but at least it works for now)

  • Hi Xiao,
    I attempted to redo the setup from the start and I’m now stuck – after configuring thunderbird and trying to send an email – I’m getting the following error :

    Sending of the message failed.
    An error occurred while sending mail: Unable to establish a secure link with Outgoing server (SMTP) mail.thevadasan.com using STARTTLS since it doesn't advertise that feature. Switch off STARTTLS for that server or contact your service provider.

    I’m assuming it is listening on port 587:

    pt@mail:~$ sudo netstat -lnpt | grep master
    tcp        0      0 0.0.0.0:587             0.0.0.0:*               LISTEN      15523/master        
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1292/nginx: master  
    tcp        0      0 0.0.0.0:465             0.0.0.0:*               LISTEN      15523/master        
    tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      15523/master        
    tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1292/nginx: master  
    tcp6       0      0 :::587                  :::*                    LISTEN      15523/master        
    tcp6       0      0 :::80                   :::*                    LISTEN      1292/nginx: master  
    tcp6       0      0 :::465                  :::*                    LISTEN      15523/master        
    tcp6       0      0 :::25                   :::*                    LISTEN      15523/master        
    tcp6       0      0 :::443                  :::*                    LISTEN      1292/nginx: master  
    
    • Your submission service on port 587 advertises STARTTLS. Always check the mail log (/var/log/mail.log) when something went wrong.

      • I’m getting some errors on the RSA keys, from the priv.key – i’ve checked that the file exists. I’m not sure how to interpret this –

        
        Sep 13 14:14:16 mail postfix/submission/smtpd[9866]: warning: cannot get RSA private key from file "/etc/letsencrypt/live/mail.thev>
        Sep 13 14:14:16 mail postfix/submission/smtpd[9866]: warning: TLS library problem: error:02001002:system library:fopen:No such file>
        Sep 13 14:14:16 mail postfix/submission/smtpd[9866]: warning: TLS library problem: error:20074002:BIO routines:file_ctrl:system lib>
        Sep 13 14:14:16 mail postfix/submission/smtpd[9866]: warning: TLS library problem: error:140B0002:SSL routines:SSL_CTX_use_PrivateK>
        Sep 13 14:14:20 mail postfix/submission/smtpd[9866]: warning: hostname client-2a0d-7c40-3000-b8b--3.hostwindsdns.com does not resol>
        Sep 13 14:14:20 mail postfix/submission/smtpd[9866]: connect from unknown[2a0d:7c40:3000:b8b::3]
        

        However, I did notice that when I tried to get a certificate I ran into the following issue – which i had interpreted it as a warning since it installed the certificate :

        Traffic on port 80 already redirecting to ssl in /etc/nginx/conf.d/mail.thevadasan.com.conf
        Failed staple-ocsp for mail.thevadasan.com
        Unable to set enhancement staple-ocsp for mail.thevadasan.com
        An error occurred while enabling OCSP stapling for {'*.thevadasan.com'}.
        
        IMPORTANT NOTES:
         - We were unable to set up enhancement staple-ocsp for your server,
           however, we successfully installed your certificate.
         - Congratulations! Your certificate and chain have been saved at:
           /etc/letsencrypt/live/mail.thevadasan.com/fullchain.pem
           Your key file has been saved at:
           /etc/letsencrypt/live/mail.thevadasan.com/privkey.pem
           Your cert will expire on 2020-12-11. To obtain a new or tweaked
           version of this certificate in the future, simply run certbot again
           with the "certonly" option. To non-interactively renew *all* of
           your certificates, run "certbot renew"
        
        

        Would this have anything to do with this issue with STARTTLS ? I’m running a wordpress site as another virtual host on nginx and I had obtained a certificate that is renewing and then tried to set up Postfix.

    • It seems you didn’t correctly enter the path for your TLS private key in /etc/postfix/main.cf file. The path is not complete.

      /etc/letsencrypt/live/mail.thev
      • yes, you’re correct there was an error with the path. I had a typo on privkey.pem

  • Thanks you for the excellent guide!

    I’ve been successful with creating the relay according to your relevant guide (sent confirmed it using the “mail example@domain.com”). I’ve also been successful in connecting via IMAP from a mail client (Mac Mail client).

    However, when trying to use the SMTP via Mac Mail client, I’m unsuccessful. Why could this be?

    Thank you so much, and please accept my small donation 🙂

    Here are a failed log (from Mail client) and a success log (from mail “my@gmail.com” command):

    Sep 23 05:30:04 mail postfix/smtpd[92233]: connect from unknown[my.client.ip.address]
    Sep 23 05:30:05 mail postfix/smtpd[92233]: Anonymous TLS connection established from unknown[my.client.ip.address]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
    Sep 23 05:30:06 mail postfix/smtpd[92233]: NOQUEUE: reject: RCPT from unknown[my.client.ip.address]: 454 4.7.1 : Relay access denied; from= to= proto=ESMTP helo=
    Sep 23 05:30:06 mail postfix/smtpd[92233]: disconnect from unknown[my.client.ip.address] ehlo=2 starttls=1 mail=1 rcpt=0/1 quit=1 commands=5/6
    Sep 23 05:30:24 mail postfix/smtpd[92233]: connect from unknown[my.client.ip.address]
    Sep 23 05:30:24 mail dovecot: imap-login: Login: user=, method=PLAIN, rip=my.client.ip.address, lip=10.128.0.3, mpid=92237, TLS, session=
    Sep 23 05:30:25 mail dovecot: imap(danny@my-new-server.com): Logged out in=32 out=515 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
    Sep 23 05:30:25 mail postfix/smtpd[92233]: Anonymous TLS connection established from unknown[my.client.ip.address]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
    Sep 23 05:30:25 mail postfix/smtpd[92233]: disconnect from unknown[my.client.ip.address] ehlo=2 starttls=1 quit=1 commands=4
    Sep 23 05:30:29 mail postfix/smtpd[92233]: connect from unknown[my.client.ip.address]
    Sep 23 05:30:30 mail postfix/smtpd[92233]: Anonymous TLS connection established from unknown[my.client.ip.address]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
    Sep 23 05:30:31 mail postfix/smtpd[92233]: NOQUEUE: reject: RCPT from unknown[my.client.ip.address]: 454 4.7.1 : Relay access denied; from= to= proto=ESMTP helo=
    Sep 23 05:30:31 mail postfix/smtpd[92233]: disconnect from unknown[my.client.ip.address] ehlo=2 starttls=1 mail=1 rcpt=0/1 quit=1 commands=5/6
    ...
    Sep 23 05:33:59 mail postfix/pickup[92192]: 17C5313E9D6: uid=1002 from=
    Sep 23 05:33:59 mail postfix/cleanup[92282]: 17C5313E9D6: message-id=
    Sep 23 05:33:59 mail postfix/qmgr[92193]: 17C5313E9D6: from=, size=421, nrcpt=1 (queue active)
    Sep 23 05:33:59 mail postfix/smtp[92284]: Untrusted TLS connection established to smtp.sendgrid.net[167.89.123.53]:587: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
    Sep 23 05:33:59 mail postfix/smtp[92284]: 17C5313E9D6: to=, relay=smtp.sendgrid.net[167.89.123.53]:587, delay=0.47, delays=0.02/0.02/0.35/0.08, dsn=2.0.0, status=sent (250 Ok: queued as MDDkRGxuSC28fIdiuMOxPA)
    Sep 23 05:33:59 mail postfix/qmgr[92193]: 17C5313E9D6: removed
    
    • It seems your Mac mail client is trying to connect to port 25 of the mail server when sending emails. You should configure the mail client to connect to port 587 or 465.

      • Danny Albocher
        19 mins ago

        Thanks for the reply! Why shouldn’t the mail client connect with my server on port 25 (incoming)? If I understood you correctly, the client can connect with my server on 25, and my server will communicate with the world via relay (which it seems like it does successfully from the fact that “mail …” worked.

    • Port 25 is usually used for MTA to MTA communication. MTA stands for Mail Transfer Agent, aka SMTP server.

      Your mail client is MUA (Mail User Agent). Port 587 and 465 are used for MUA to MTA communication.

      Most residential ISPs block port 25. It doesn’t make sense for mail clients to use port 25 to submit outgoing emails.

      • Danny Albocher
        5 seconds ago

        Thanks. Understood. Interesting then that that was the default for the Mail client.

        Switched to 587, and it worked!

        Thanks 🙂

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.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.


The maximum upload file size: 2 MB.
You can upload: image.