How I set up my email in Emacs with mu4e and mbsync/isync
This was a true pain to do, because I am using protonmail which only will work with local clients trough a bridge. But now the pain is over, and I can document the process so others can benefit from it, and maybe have less of a problem with it.
I departed from this excellent tutorial for how to get protonmail up and running with mu4e and Emacs: https://doubleloop.net/2019/09/06/emacs-mu4e-mbsync-and-protonmail/
It took some time for me to get my head around the fact that three things are needed to get mu4e working as I expected.
- something to recieve and sort the mail so mu4e can find it (IMAP via mbsync)
- something to send the mail (SMTP) so mu4e can ship the mail.
- mu4e to administer both these functions.
IMAP (recieving emails)
So first I had to setup the bridge for IMAP.
I found this excellent guide on getting it done: https://doubleloop.net/2019/09/06/emacs-mu4e-mbsync-and-protonmail/
and copied this script, with a few corrections inserted below to both a mbsyncrc file and a .config/isyncrc file (because it said mbsyncrc everywhere, but whenever I tried to run index in bash, it kept demanding a isyncrc also:
IMAPAccount protonmail Host 127.0.0.1 Port 1143 User YOUREMAIL@protonmail.com Pass YOURPASSWORD TLSTYPE STARTTLS CertificateFile ~/.cert/protonmail.crt IMAPStore remote Account protonmail #You can change mail to something else MaildirStore local Path ~/mail/ Inbox ~/mail/INBOX/ #You can change .mail to something else MaildirStore local Path ~/mail/ Inbox ~/mail/INBOX/ Channel inbox Far :remote: Near :local: Patterns INBOX* !"Drafts" !"All Mail" Create Near #Expunge Both SyncState * Group protonmail Channel inbox
The most important correction was to add INBOX before the * in Patterns, since I had issues after the full setup with this warning:
Maildir warning: ignoring INBOX
Also, it's important to note, that to get the certificate I followed advice from this reddit post:
I will write it here also, to keep for posterity, in case reddit goes haywire:
To use mbsync over a secure connection add TLSType STARTTLS TLSVersions TLSv1.2 CertificateFile ~/.cert/protonmail.crt to .mbsyncrc and put the certificate generated by openssl s_client -starttls imap -connect 127.0.0.1:1143 -showcerts in ~/.cert/protonmail.crt, i.e. the lines between (and including) -----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----
Then I could run:
mu index
and
mbsync protonmail
in my terminal, and the sync got set up and indexed.
SMTP (Sending emails)
To get SMTP up and running as well, so I can get the full joy of mu4e (not having to leave emacs at all, that is) I only had to make a file named .authinfo as described in This tutorial on doubleloop.net
machine 127.0.0.1 login USERNAME_HERE@protonmail.com port 1143 password PASSWORD_PROVIDED_BY_BRIDGE machine 127.0.0.1 login USERNAME_HERE@protonmail.com port 1025 password PASSWORD_PROVIDED_BY_BRIDGE
Note on mbsyncrc and isyncrc
I both set up an .mbsyncrc and an isyncrc, but mbsync only seems to read the latter, so it might be advisable to get rid of the former, however strange this seems.
mu4e
This took me a while, because I had to figure out where the h*?%&! my mu4e had gone after install…
This took me a while and some asking around - especially in #Emacs:matrix.org where the community was great. One of the reasons I fell for emacs in the first place.
I finally found it, by typing
which mu4e
Then I could add the correct value to my init.el:
;;========= E-POST MED mu4e ================ ;; setting mu4e to executable path & require (add-to-list 'load-path "/usr/share/emacs/site-lisp/elpa-src/mu4e-1.8.14") (setq mu4e-mu-binary "/usr/bin/mu") (require 'mu4e) ;; SMTP from https://doubleloop.net/2019/09/06/emacs-mu4e-mbsync-and-protonmail/ (setq mu4e-maildir "~/mail" mu4e-attachment-dir "~/downloads" mu4e-sent-folder "/Sent" mu4e-drafts-folder "/Drafts" mu4e-trash-folder "/Trash" mu4e-refile-folder "/Archive") (setq user-mail-address "YOUR_EMAIL_ADDRESS" user-full-name "YOUR_FULL_NAME") ;; Get mail (setq mu4e-get-mail-command "mbsync protonmail" mu4e-change-filenames-when-moving t ; needed for mbsync mu4e-update-interval 120) ; update every 2 minutes ;; Send mail with SMTP (setq message-send-mail-function 'smtpmail-send-it smtpmail-auth-credentials "~/.authinfo.gpg" smtpmail-smtp-server "127.0.0.1" smtpmail-smtp-service 1025)
THEN I could finally call 'M-x mu4e' and get to read and send emails and be happy :)