Dovecot 2 + PostgreSQL

dovecot.conf

protocols = imap pop3
auth_mechanisms = PLAIN
log_timestamp = "%Y-%m-%d %H:%M:%S «
mail_location = maildir:/home/vmail/%d/%n/Maildir
shutdown_clients = yes

ssl = yes
ssl_cert = </etc/ssl/certs/dovecot.pem
ssl_key = </etc/ssl/private/dovecot.pem

disable_plaintext_auth = yes
auth_default_realm =  # there is maybe domain name.

login_greeting = Welcome to best email server.
 
namespace {
  type = private
  separator = .
  prefix = INBOX.
  inbox = yes
}

service imap-login {
  inet_listener imap {
    port=0
  }
}

service pop3-login {
  inet_listener pop3 {
    port=0
  }
}

log_path = /var/log/dovecot.log
info_log_path = /var/log/dovecot-info.log
 
protocol pop3 {
  pop3_uidl_format = %08Xu%08Xv
  ssl_listen = *:995
}

protocol imap {
  ssl_listen = *:993
}

auth_verbose = yes

auth default {
  user = dovecot
 
  passdb sql {
    args = /etc/dovecot/dovecot-sql.conf
  }

  userdb static {
    args = uid=5000 gid=5000 home=/home/vmail/%d/%n allow_all_users=yes
  }
 
  socket listen {
    master {
      path = /var/run/dovecot/auth-master
      mode = 0600
      user = vmail
    }
 
    client {
      path = /var/run/dovecot/auth-client
      mode = 0660
      user = Debian-exim
      group = Debian-exim
    }
  }

#This part contains sockets for my exim server
service auth {
    unix_listener auth-master {
      mode = 0600
      user = Debian-exim
      group = Debian-exim
    }
    unix_listener auth-client {
      mode = 0660
      user = Debian-exim
      group = Debian-exim
    }
}
}

 

dovecot-sql.conf
driver = pgsql                                                                                                                                                                                                                               
connect = host=pg-master.local dbname=maildb user=mailadmin password=mailpassword                                                                                                                                                                    
default_pass_scheme = PLAIN-MD5                                                                                                                                                                                                              
password_query = SELECT email AS user, password FROM users WHERE email = '%u';

Table users:
mail=> \d users;    
             Table „public.users“                                                                                                                                                                                                            
  Column  |         Type          | Modifiers                                                                                                                                                                                                
----------±----------------------±----------                                                                                                                                                                                               
 email    | character varying (80) | not null                                                                                                                                                                                                 
 password | character varying (32) | not null                                                                                                                                                                                                 
Indexes:                                                                                                                                                                                                                                     
    „users_pkey“ PRIMARY KEY, btree (email)

 

 

How to check with mutt (best console client):

cat > ~/.muttrc << EOF

 set spoolfile=»imaps://user:pass@server/INBOX"                                                                                                                                                                                      
 set folder="imaps://user@server/INBOX"                                                                                                                                                                                                  
 set record="=Sent"                                                                                                                                                                                                                          
 set postponed="=Drafts"   

EOF

mutt

Don't forget to read logs !