Debian Tutorials

Debian Tutorials


Step by step tutorials showing you how to install and configure various applications and services on Debian based Linux distros.

October 2024
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  

Categories


Installing Dovecot IMAP and POP daemon with MySql backend

Ástþór IPÁstþór IP

Dovecot is an open source IMAP and POP3 server for Linux/UNIX-like systems, written primarily with security in mind. Dovecot primarily aims to be a lightweight, fast and easy to set up open source mailserver.

It’s assumed that you have already installed and configured Postfix according to this tutorial:
Installing Postfix with MySql backend and SASL for SMTP authentication

1. Install required packages

apt-get install dovecot-imapd dovecot-pop3d

2. Configure Dovecot (pico /etc/dovecot/dovecot.conf)

protocols = imap imaps pop3 pop3s
ssl_disable = no
mail_location = maildir:/home/vmail/%d/%n
auth default {
passdb sql {
args = /etc/dovecot/dovecot-sql.conf
}
userdb sql {
args = /etc/dovecot/dovecot-sql.conf
}
}
disable_plaintext_auth = no
user = vmail

Add or edit the above properties and leave everything else with the default value or configure according to your needs

3. Configure the MySql connector (pico /etc/dovecot/dovecot-sql.conf)

driver = mysql
connect = host=127.0.0.1 dbname={database} user={username} password={password}
default_pass_scheme = CRYPT
password_query = SELECT email as user, password FROM users WHERE email = '%u'
user_query = SELECT CONCAT('/home/vmail/',SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/') as home, '5000' as uid, '5000' as gid FROM users WHERE email = '%u'

{database} = MySql database name
{username} = MySql username
{password} = MySql password

4. Restart Dovecot daemon

/etc/init.d/dovecot restart

Comments 6
  • arri
    Posted on

    arri arri

    Author

    Hi,

    i glued together 3 of the articles on this site, in order to create a mailsystem with postfix, dovecot(imaps), sasl (cyrus), dspam and clamav.

    i ‘seems’ everything is working, except that any mail sent TO this server will consistently gets bounced with error code 550 550 5.1.1
    Recipient address rejected: User unknown in virtual alias table (state 14).

    i already tried creating a /etc/postfix/virtual table and add the hash to virtual_alias_maps, but that’s not the solution…
    any idea where i should look?

    btw, great howto’s, especially if this problem turns out to be my own stupid fault.;)


  • aip
    Posted on

    aip aip

    Author

    Hello arri

    If you are using the MySql backend you don’t need the /etc/postfix/virtual file because the users are stored in a MySql database. Can you check the /etc/log/mail.log file, it may contain some additional information.

    -aip


  • arri
    Posted on

    arri arri

    Author

    hi aip, thanks for responding.
    actually that’s what i’m doing (log-watching). but on this issue they don’t report anything. and strange enough, watching raw traffic using tcpdump i don’t even see any traffic. ..must be doing something else wrong..


  • arri
    Posted on

    arri arri

    Author

    small additional question;
    the virtual domains mappings file from this page:
    http://www.debiantutorials.net/installing-postfix-with-mysql-backend-and-sasl-for-smtp-authentication/

    … defines “select_field = ‘virtual'” , while the table-definition only defines 1 table ‘domain’.

    is that an error? or does this work because “right-hand content does not matter” virtual(5)?


  • arri
    Posted on

    arri arri

    Author

    …and a final word 🙂

    on the internet you can find quite a numer of tuts/howto’s about setting-up a maileserver of some sort using any number and combination of an array of tools that need to be glued togerher. this glueing can become quite complex and require some serious concentration, reading etc.

    I just finished a mailsetup using 3 artikels from this site plus a dozen others for several detaills. This roughly took me a day or so to finish.

    But it took another 3 days before it was working properly, because all the time i was overlooking something very crucial, but super-obvious…

    And not even 1 of all these sites/blogs that i used as a guide makes any mention of it. It is asumed taken care of and it’s another-/offtopic etc..

    so to spare others the kind of the frustration i experienced last few days:
    if you find your setup is not acting as it should, and although still learing, you think your config is right.. also make sure to CHECK YOUR DNS RECORDS

    one of mine was changed without me knowing it.. i guess in my sub-consious just asumed they were alright.. simply never thought to double-check those

    thanks for the article, and your support,

    gvr
    a


  • aip
    Posted on

    aip aip

    Author

    Thanks for sharing you solution, hopefully it will help others.

    It’s a good point about gluing the tutorials together, usually you are not just setting up a standalone IMAP/POP server, you’ll also need a SMTP server and possibly spam filtering. I think it would be a good idea to create complete mail server setup tutorials.

    -aip