Add Default Mailbox Folders (Sent, Drafts Trash, Junk, Archive) to Dovecot

Please enable the auto creation of mail folders for new email accounts in Dovecot. This is documented in detail here:

(Current method) MailboxSettings - Dovecot Wiki
(Deprecated) Plugins/Autocreate - Dovecot Wiki

Steps to create:

We have these folders already, what is your use-case for auto-creation?

@CyberPanel said:
We have these folders already, what is your use-case for auto-creation?

Just as an update since I was too busy to reply, no, we do not already have these folders. These folders are ONLY created if you log in first in Rainloop because Rainloop, not Dovecot. If you log in for the first with iOS Mail using IMAP, only Inbox is created. So, no, we do not already have these folders. I checked in the Dovecot configuration files and CyberPanel never adds the settings for these default IMAP folders.

Here is a fix I cooked up. Before, iOS Mail would not auto generate the correct folders and you would also be required to manually map to them in the iOS Settings. Another issue was Windows 10 Mail creating its own separate folder for sent emails called “Sent Items” which is now fixed as well since all sent emails regardless of client go into the “Sent Items” folder. So now, besides with Rainloop, email folder mappings work perfectly with iOS Mail and Windows 10 Mail and likely almost any other normal email client out there.

Note, though, that unless you know what you are doing, you will want to do this on a fresh install before logging in with any email accounts especially if you are using the built-in Rainloop webmail. Otherwise, Rainloop will map to the wrong folder locations for that login user and you will then have to clear some SQL database entries and Rainloop’s cached files in its data folder from the backend (highly discouraged!). So only proceed if you are starting with a fresh install of CyberPanel, skipping the next paragraph and starting with step 5.

But if you are not using the built-in Rainloop webmail, you can easily start with what you need from a fresh installation by doing the following: (Step 1) deleting all email accounts within CyberPanel, and (Step 2) deleting all remnants of old emails within the vmail folder under the Home directory. (Step 3) You also delete any manually installed webmail clients (such as a non-stock Rainloop install or RoundCube) from their public_html directories and (Step 4) delete their respective databases. Once finished, proceed to the fifth and final step.

Step 5. Replace the namespace section in dovecot.conf under /etc/dovecot with the following and then restart the dovecot service (service dovecot restart):

namespace inbox {
inbox = yes
location =
prefix =
mailbox “Deleted Items” {
auto = create
special_use = \Trash
}
mailbox “Drafts” {
auto = create
special_use = \Drafts
}
mailbox “Archive” {
auto = create
special_use = \Archive
}
mailbox “Sent Items” {
auto = create
special_use = \Sent
}
mailbox “Junk Mail” {
auto = create
special_use = \Junk
}
}

We could use a sperate tutorial for that. :slight_smile:

1 Like

Thanks! Yesterday, I was also able to get SpamAssassin configured to move spam emails automatically to Junk with Dovecot’s Sieve plugin in Pigeonhole.

For the bulk of the setup, I followed the directions for implementing the Spam sieve as described here:

Among the few notable differences was I skipped ahead to “II - Move your SPAM to the Junk folder:” since Dovecot is already online.

For sub-step 4, since this CentOS and not Ubuntu, I use “yum install dovecot-pigeonhole” instead of “apt-get install dovecot-sieve” as described here in the CentOS forums:
https://www.centos.org/forums/viewtopic.php?p=22543#p22543

Following the StackOverflow guide, I also skip sub-steps 1, 3, 4, and 5. I instead do the .conf file configuration in the Dovecot.conf file in the place of the conf.d/*.conf files as described in this other guide here:

Since I implemented “Junk Mail” as my spam folder name, I use the spam folder name of “Junk Mail” to match my configuration in step 7.


When I get the time, I hope to also figure out how to train SpamAssassin’s Bayes feature in learn-sa and IMAPSieve so that whenever emails are marked as Spam or Not Spam, any future emails from the marked addresses go to spam or the inbox instead. I have been combing through these links and it has not worked out yet but I will eventually get this one sorted out:

https://wiki2.dovecot.org/HowTo/AntispamWithSieve

Followed step 5, worked like a charm. Thank you for this tip Hifihedgehog!

1 Like