This documentation is for Dovecot v2.x, see wiki1 for v1.x documentation.

Restricting Access

Restricting IMAP access

If you want to give POP3 access to everyone, but IMAP access only for some people, you have to use passdb which allows selecting this.


Set PAM service name to *, ie.:

passdb pam {
  args = *

That way PAM uses /etc/pam.d/imap for IMAP, and /etc/pam.d/pop3 for POP3.

In /etc/pam.d/imap you could then use eg. module:

# allow IMAP access only user only if it's in /etc/imapusers file
auth    required item=user sense=allow file=/etc/imapusers onerr=fail


You can use %s variable which expands to imap or pop3 in password_query, eg:

password_query = SELECT password FROM users WHERE userid = '%u' and (imap_allowed = true or '%s' = 'pop3')


Just like with SQL, you can use %s in pass_filter, eg.:

pass_filter = (&(objectClass=posixAccount)(uid=%u)(service=%s))

That would reqire having both service=pop3 and service=imap objects though. Maybe there are other ways, I'm not very good at LDAP.

Restricting IP Access

It's possible to allow user to authenticate only from a specific IP or network. This is especially useful for master users. This can be done by returning allow_nets extra field in passdb.