Luciano Laratelli

Setting up mu4e with iCloud custom domains with Doom Emacs on Arch Linux

2022-04-19


Here's how I set up mu4e with Doom Emacs on Arch Linux for my custom domainhosted on iCloud. I'm using mbsync, mu, and msmpt. I originally went witha systemd timer as detailed in the first two sections as recommended in the Arch, but mu4e actually has a built-in functionality to deal with this for us.Note that what I've written here is the minimum I needed to do to actuallysync, send, and read emails from emacs. There's a lot more you can do.

Configuration files

In init.el, under :email

(mu4e +org)

config.el:

(set-email-account! "icloud"
  '((mu4e-sent-folder       . "/icloud/Sent")
    (mu4e-drafts-folder     . "/icloud/Drafts")
    (mu4e-trash-folder      . "/icloud/Trash")
    (mu4e-refile-folder     . "/icloud/Archive")
    (smtpmail-smtp-user     . "lucianolaratelli")
    (mu4e-compose-signature . "\n\nLuciano"))
  t)

(after! mu4e
  (setq sendmail-program (executable-find "msmtp")
        send-mail-function #'smtpmail-send-it
        smtpmail-stream-type 'starttls
        message-sendmail-f-is-evil t
        message-sendmail-extra-arguments '("--read-envelope-from")
        message-send-mail-function #'message-send-mail-with-sendmail))

In $HOME/.config/system/user/mbsync.timer:

$HOME/.config/system/user/mbsync.service:

$HOME/.mbsyncrc:

The crucial part when you're using a custom domain hosted on iCloud is to useyour iCloud email address instead of the custom one. I thought this was a bugwith custom domains (I've run into another one) but I called Apple's support andthey told me I needed to use the iCloud email address. You can find this on aniPhone or iPad by going to Settings, tapping on your name up top, and tapping onName, Phone Numbers, Email. I had @me.com and @icloud.com emails there. Iwent with the @icloud.com one. Apple's docs on third-party iCloud clients sayyou can use just the part before the domain, but I included the whole thing justin case. Without further ado, $HOME/.msmptrc:

I have tls and tls_starttls both on. I think I only need one of these, but Idon't want to muck with testing my mail configuration to get a blog post out.You might need one, the other, or both. Exercise for the reader!

I was originally using gpg as described by Erich Grunewald in his very helpfulpost, but unlocking my yubikey every five minutes became a pain and I figured mylogin keychain was secure enough for my (unsophisticated) threat model.

Install and enable packages

yay mbsync
sudo pacman -S msmtp
yay mu mu4e # impossible to find mu otherwise

mkdir -p ~/home/Dropbox/mailbox/icloud
mbsync -Va
mu init -m ~/Dropbox/mailbox --my-address luciano@laratel.li
mu index

systemctl enable --user --now mbsync
systemctl enable --user --now mbsync.timer

doom sync

At this point you can run emacs, <SPC> o m, and get to emailin'!

Moving away from systemd

This was working fine but I wasn't getting in-emacs notifications when newemails came in, even though mbsync was running on schedule! So I got rid ofthe mbsync.timer service with systemctl disable --now --user mbsync.timer. Ikept mbsync.service so that my email syncs when I log in for the day. Then, inmy config.el:

(after! mu4e (setq mu4e-get-mail-command "mbsync --verbose --all"
                   mu4e-update-interval 300))

I restarted emacs and I was good to go.

Resources

Tecosaur's awe-inspiring config

The already-mentioned post from Erich Grunewald

The Doom Emacs mu4e module documentation (also from Tecosaur)

davemail

This article, though it focuses on macOS