Dovecot-storage configuration

<!-- NOTES - Notes here --> <!-- GOAL ONE-LINER --> <p>Configure how dovecot will store the received e-mails.</p> <!-- RATIONALE --> <!-- NUANCE --> <h2>Procedure</h2> <!-- NARRATIVE FORM --> <!-- STEP BY STEP --> <ol> <li> <p>Create user, group and a corresponding homedir to have an entity that can write to the file system:</p> <pre><code class="language-shell">useradd --create-home --uid 5000 --home-dir /var/vmail vmail</code></pre> </li> <li> <p>Edit <code>/etc/dovecot/conf.d/10-mail.conf</code> to make Dovecot stop using the default mail storage path and use the path defined in the database instead:</p> <pre><code class="language-diff"> # 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 # # &lt;doc/wiki/MailLocation.txt&gt; # - mail_location = mbox:~/mail:INBOX=/var/mail/%u + mail_location = maildir:%h/Maildir</code></pre> <blockquote> <p><code>%h</code> placeholder to be filled with SQL data as defined in <a href="/mailserver/dovecot-storage-config/Mail-server_Dovecot-MySQL-configuration">Dovecot-MySQL config</a>.</p> </blockquote> </li> <li> <p>Edit <code>/etc/dovecot/conf.d/10-master.conf</code> to have it create a <a href="https://en.wikipedia.org/wiki/Unix_file_types#Socket">socket file</a> for the user/group postfix with 660 as its user permissions (so only "postfix" can "talk to" the socket file):</p> <pre><code class="language-diff"> service lmtp { - unix_listener lmtp { - #mode = 0666 + unix_listener /var/spool/postfix/private/dovecot-lmtp { + mode = 0660 + user = postfix + group = postfix }</code></pre> </li> <li> <p>Tell postfix to use dovecot-lmtp as its Local Mail Transfer Protocol (LMTP) for delivery:</p> <pre><code class="language-shell">postconf -e "virtual_transport=lmtp:unix:private/dovecot-lmtp"</code></pre> </li> <li> <p>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:</p> <pre><code class="language-shell">postconf -e 'mydestination = localhost, localhost.localdomain, localhost'</code></pre> </li> <li> <p>Edit <code>/etc/dovecot/conf.d/15-mailboxes.conf</code> to have clients automatically optionally create, and subsequently subscribe to the standard folders in mailboxes:</p> <pre><code class="language-diff">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 }</code></pre> </li> <li> <p>Reload the configuration files into Dovecot and Postfix to effectuate the changes:</p> <pre><code class="language-shell">service dovecot reload service postfix reload</code></pre> </li> </ol> <!-- REFERENCES -->