Mail server_Dovecot storage configuration - SomethingWithHorizons/mailserver GitHub Wiki

Configure how dovecot will store the received e-mails.

Procedure

  1. Create user, group and a corresponding homedir to have an entity that can write to the file system:

    useradd --create-home --uid 5000 --home-dir /var/vmail vmail
    
  2. Edit /etc/dovecot/conf.d/10-mail.conf to make Dovecot stop using the default mail storage path and use the path defined in the database instead:

      # See doc/wiki/Variables.txt for full list. Some examples:
      #
      #   mail_location = maildir:~/Maildir
      #   mail_location = mbox:~/mail:INBOX=/var/mail/%u
      #   mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
      #
      # <doc/wiki/MailLocation.txt>
      #
    - mail_location = mbox:~/mail:INBOX=/var/mail/%u
    + mail_location = maildir:%h/Maildir
    

    %h placeholder to be filled with SQL data as defined in Dovecot-MySQL config.

  3. Edit /etc/dovecot/conf.d/10-master.conf to have it create a socket file for the user/group postfix with 660 as its user permissions (so only "postfix" can "talk to" the socket file):

      service lmtp {
    -   unix_listener lmtp {
    -     #mode = 0666
    +  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    +    mode = 0660
    +    user = postfix
    +    group = postfix
      }
    
  4. Tell postfix to use dovecot-lmtp as its Local Mail Transfer Protocol (LMTP) for delivery:

    postconf -e "virtual_transport=lmtp:unix:private/dovecot-lmtp"
    
  5. Have your FQDN removed from '/etc/postfix/main.cf' to prevent mails to your FQDN being handled via the system delivery process, and instead use the virtual delivery process:

    postconf -e 'mydestination = localhost, localhost.localdomain, localhost'
    
  6. Edit /etc/dovecot/conf.d/15-mailboxes.conf to have clients automatically optionally create, and subsequently subscribe to the standard folders in mailboxes:

    mailbox Drafts {
    + auto = subscribe
      special_use = \Drafts
    }
    
    mailbox Junk {
    +  auto = subscribe
       special_use = \Junk
    }
    mailbox Trash {
    +  auto = subscribe
       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 = subscribe
       special_use = \Sent
    }
    
  7. Reload the configuration files into Dovecot and Postfix to effectuate the changes:

    service dovecot reload
    service postfix reload