Configuring Dovecot IMAP for SENT and TRASH Folders: Cross-Client Compatibility Setup


3 views

When deploying Dovecot IMAP servers, one common frustration is the lack of standard special folders (SENT, TRASH, DRAFTS) that most email clients expect. While Dovecot doesn't create these by default, we can properly configure them for optimal client compatibility.

The key to proper folder setup lies in Dovecot's namespace configuration. Here's a basic implementation in dovecot.conf:

namespace {
  type = private
  separator = /
  prefix = 
  inbox = yes
  location = 

  mailbox Sent {
    auto = subscribe
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    auto = no
    special_use = \Sent
  }
  mailbox Trash {
    auto = subscribe
    special_use = \Trash
  }
}

Different clients use different names for special folders. This extended configuration handles multiple naming conventions:

namespace {
  # ... previous namespace config ...

  # Sent folder variants
  mailbox "Sent" {
    auto = no
    special_use = \Sent
  }
  mailbox "Sent Items" {
    auto = no
    special_use = \Sent
  }
  mailbox "Sent Messages" {
    auto = subscribe
    special_use = \Sent
  }

  # Trash folder variants
  mailbox "Trash" {
    auto = subscribe
    special_use = \Trash
  }
  mailbox "Deleted Items" {
    auto = no
    special_use = \Trash
  }
}

To place these folders at the root level rather than under INBOX, modify the location parameter:

namespace {
  type = private
  separator = /
  prefix = 
  inbox = yes
  location = maildir:~/Maildir

  # Root-level folders
  mailbox Sent {
    auto = subscribe
    special_use = \Sent
  }
  mailbox Trash {
    auto = subscribe
    special_use = \Trash
  }
}

For iPhone (iOS Mail) specifically, we need to ensure proper folder mapping:

plugin {
  mail_attribute_dict = file:%h/Maildir/dovecot-attributes
}

protocol imap {
  mail_plugins = $mail_plugins imap_special_use
}

After configuration, verify with:

doveadm mailbox list -u username
doveadm mailbox status -u username all

For a complete implementation with all special folders (including Drafts and Junk), consider:

namespace inbox {
  mailbox Drafts {
    special_use = \Drafts
    auto = subscribe
  }
  mailbox Junk {
    special_use = \Junk
    auto = subscribe
  }
  mailbox Trash {
    special_use = \Trash
    auto = subscribe
  }
  mailbox Sent {
    special_use = \Sent
    auto = subscribe
  }
}

When setting up Dovecot as your IMAP server, you'll notice it doesn't automatically create special-use mailboxes like Sent or Trash. The default configuration typically only includes the INBOX hierarchy. This can cause compatibility issues with mobile email clients (iOS Mail, Outlook Mobile, etc.) that expect these standard folders to exist.

The IMAP protocol supports special-use mailboxes through the SPECIAL-USE extension (RFC 6154). These include:


\Sent - For sent messages
\Trash - For deleted messages
\Drafts - For draft messages
\Junk - For spam messages
\Archive - For archived messages

To properly configure these folders, you'll need to modify your Dovecot configuration (typically in /etc/dovecot/conf.d/15-mailboxes.conf):


namespace inbox {
  mailbox Sent {
    auto = subscribe
    special_use = \Sent
  }
  mailbox Trash {
    auto = subscribe
    special_use = \Trash
  }
  mailbox Drafts {
    auto = subscribe
    special_use = \Drafts
  }
  mailbox Junk {
    auto = subscribe
    special_use = \Junk
  }
  mailbox Archive {
    auto = subscribe
    special_use = \Archive
  }
}

To place these folders at the root level (outside INBOX hierarchy), you would use:


namespace {
  prefix =
  separator = /
  inbox = no
  
  mailbox Sent {
    special_use = \Sent
  }
  mailbox Trash {
    special_use = \Trash
  }
}

namespace inbox {
  separator = /
  prefix = INBOX.
  inbox = yes
}

Different clients expect different folder names. To ensure maximum compatibility:


mail_plugins = $mail_plugins listescape

plugin {
  listescape_slashes = no
  listescape_char = \
}

namespace inbox {
  mailbox Sent {
    auto = subscribe
    special_use = \Sent
    alias = Sent Messages
  }
  mailbox Trash {
    auto = subscribe
    special_use = \Trash
    alias = Deleted Items
  }
}

After configuration, test with:


doveadm mailbox list -u username "*"
doveadm mailbox status -u username "INBOX" all

For iOS specifically, you may also want to add:


mailbox "Sent Messages" {
  auto = subscribe
  special_use = \Sent
}
mailbox "Deleted Messages" {
  auto = subscribe
  special_use = \Trash
}

Ensure the folders are automatically created and subscribed for new users:


mailbox auto = subscribe
mailbox auto = create