How to Setup Postfix Mail Server and Dovecot with Database (MariaDB) Securely – Part 1

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Gabriel Cánepa

Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

43 Responses

  1. Rodrigo says:

    I’d just like to point out that the function ENCRYPT is not available in MySQL 8 and that one has to use other stronger mean of encryption. I know here we are supposed to use MariaDB but I must use mysql. The function that worked for me up to this point is SHA2 and the syntax works like this:

    INSERT INTO Users_tbl (DomainId, password, Email) VALUES (1, SHA2('mypassword', 256), '[email protected]');

    Albeit there are stronger algorithms, at least implementing this one was easy and fast. I found that Bcrypt is recommended by experts but I thing it might be more difficult to implement.

    Hopefully someone else finds this useful.

  2. Paul says:

    Does this still work currently for new linux and other packages?

  3. Armin says:

    Any plan to update this guide for latest systems and package versions?

  4. Son MengLeang says:

    Can you list step-by-step of configuration Mariadb store user mail account I young of knowledge of Mariadb I really need help


  5. Eric Evans says:

    I have a Centos 7 mail and web server combo using the mariadb for email accounts. I would like to add wordpress db for multiple websites instead of the traditional web server.

    Any insights on how to accomplish this? I tried to add the wordpress db and had issues and would like to have multiple instances of wordpress for multiple sites.

    I appreciate any help you can give me.

  6. Viki says:

    Great article series. Quite detailed & extensive but I could not find any way to restrict the user mail accounts in size. I mean how can one restrict the mailboxes maximum size to some arbitrary amount to save the system from getting completely filled up by a runaway user.
    Or maybe I overlooked some configuration detail.

    • Viki says:

      Replying to my own comment. Well, Isn’t there any configuration for mail quotas in the this setup ? I think that is the missing piece & will complete the scenario. Thanks.

      • Viki says:

        Hello Everybody,

        Is the comment section closed ? I was expecting some sort of a reply to my query on Quota Enforcement. Many Thanks…

        • Vincent Stans says:

          If you have read through the setup you must have noticed the Directory /etc/dovecot/conf.d/ where all dovecot configuration files are stored.

          Take a look at 90-quota.conf and adjust to your needs.

  7. Dieter Raith says:

    I was struggling for days to find out, why I always got password mismatches. After debugging dovecot auth-worker and creating the password

    doveadm pw -p myfirstpassword -s sha512

    I found that $6$………………………. is no longer valid with dovecot version 2.2.13

    When I took the complete string:


    and put it into the password field of the SQL Database I could login with user and password.

    I am using maria-db (mysql Ver 15.1 Distrib 10.0.30-MariaDB, for debian-linux-gnu (x86_64)) which is a opensource fork of mysql. I cannot imagine that this caused the problem. So please update Your great tutorial accordingly.

    • Vincent Stans says:

      Thanks for your comments this solved my Authentication Failure with the clients.

      Dist: Ubuntu 16.04
      mysql Ver 15.1 Distrib 10.0.31-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

      dovecot –version
      2.2.22 (fe789d2)

  8. geoff says:

    Thanks for the wonderful tutorial, that’s a lot of work!

    One problem, though in your “Users_tbl”, the password field needs to be longer, maybe “varchar(110)” rather than “varchar(100)”. The SHA512 hash is several characters too long, so gets automatically truncated. I spent quite a few hours on this before I could successfully log in!

    • Jimmy says:

      I have confirmed the above comment, using varchar 100 caused password mismatch as the return hash value is 106, needs to be extended. Other than that a great guide.

  9. David says:

    Thank you very much for these 5 articles, but I would like How to Setup Postfix Mail Server and Dovecot With the directory ldap of samba4 ?

    Thank you for your responses.

  10. yassine says:


    Thank you so much for this article, I am stuck in section 13 I got this error code #1005 – Can’t create table ‘ZeemailServer_db.Users_tbl’ (error: 150)

    maybe I have done something wrong


Got something to say? Join the discussion.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.