Using mu4e with

Alright. At some point in time any Emacs user wants to figure out how he or she can read and write mails using Emacs. Personally I'm not really a fan, but I'll give you a configuration that works with on Linux. It took me a lot of online searching and reading other peoples blog posts to stitch this together, so maybe this will help another lost soul.

Let's start with the OS setup. We need the package isync (which contains the mbsync binary) and mu4e (which ships mu and also some Emacs code):

sudo apt install isync mu4e

Next we'll configure mbsync using a ~/.mbsyncrc configuration file:

IMAPStore mailbox-remote
Pass super-secret-password

MaildirStore mailbox-local
Path ~/Mail/
Inbox ~/Mail/Inbox
Subfolders Verbatim

Channel mailbox
Far :mailbox-remote:
Near :mailbox-local:
Patterns *
SyncState *
Create Both
Expunge Both
CopyArrivalDate yes

Note: The Pass config section can also be replaced by PassCmd.

And we will also add a ~/.authinfo file so that we can send mails:

  port 587
  password super-secret-password

After this we can create a local directory with all our mail data:

mkdir ~/Mail
mbsync -a
mu init --maildir=~/Mail
mu index

And finally we can configure Emacs. The below folder/maildir structure is based on the default folder structure that you find in your account:

(use-package mu4e
  (setq user-full-name "Your Name"
        user-mail-address ""
        mu4e-change-filenames-when-moving t
        mu4e-get-mail-command "mbsync -a"
        mu4e-attachment-dir "~/Downloads"
        mu4e-drafts-folder "/Drafts"
        mu4e-sent-folder "/Sent"
        mu4e-refile-folder "/Archive"
        mu4e-trash-folder "/Trash"
        mu4e-maildir-shortcuts '((:maildir "/Inbox" :key ?i)
                                 (:maildir "/Sent" :key ?s)
                                 (:maildir "/Trash" :key ?t)
                                 (:maildir "/Drafts" :key ?d)
                                 (:maildir "/Junk" :key ?j)
                                 (:maildir "/Archive" :key ?a))
        smtpmail-smtp-server ""
        smtpmail-smtp-service 587
        smtpmail-stream-type 'starttls
        send-mail-function 'smtpmail-send-it))

Published: 2024-06-01