Muto's Shack - Weblog - Projects - Microblog
I've been using rmail (an email client built-in to Emacs) on and off for some 5 years now. I have used mutt, thunderbierd, notmuch, m4ue, claws, gmail, geary, evolution, and a handful of others, but I like rmail. I have a healthy relationship with rmail and, although I have written sections on it, and made a few videos about it, I owe rmail at least one good article, so here we go!
I'll only be talking about how to access email from a generic remote inbox, since that's what I have.
You're going to want to add this code into your emacs configuration file (I have mine in ~/.emacs.d/init.el but yours might just be in ~/.emacs.
(setq rmail-primary-inbox-list (list (concat "imaps://shack%40muto.ca" ":Passw0rD" "@mail.gandi.net")) send-mail-function 'smtpmail-send-it rmail-preserve-inbox t rmail-file-name "~/.emacs.d/mymail/muto" user-mail-address "shack@muto.ca" user-full-name "Muto")
Looking good! First we tell Emacs what our email address is, which uses the same syntax as the MAIL environment variable! It looks like this:
Protocol://Username:Password@Host
I cut it up into multiple lines for readability using the 'concat' function. Notice that I use %40 instead of @. This is how the MAIL environment variable works. It's not bad, but it's a quirk that we just have to live with.
Then we set some variables:
Looking good so far! Let's test it out to make sure it works.
Start rmail with M-x rmail, then use 'h' to view your inbox, and 'g' to attempt to get new mail. (If you're stuck here, let me know. I want this guide to be straightfofrward)
Send an email with 'm' to whoever you want (me, maybe?) and that should be it! In the inbox summary view you can use 'n' and 'p' to move up and down through your emails, and 'o' to send an email to another file.
When you send an email to a different file via 'o', it appends it to (or creates a new) file that is exactly the same as your inbox file, so you can have different "folders" by creating different rmail files! I usually have files named 'conv' and 'note' to sort between conversational emails and website notification/junk emails! It's nice
Note that, when you copy an email to a new file, it remains in your inbox. You can safely delete it from your inbox, since the copy is in another file.
Quick PSA, download your email and store them locally. If you set 'rmail-preserve-inbox' to 't' (like in the example), every time you refresh your inbox, your entire local inbox will be duplicated! I added it just so you wouldn't be surprised to find all your mail gone while you're using rmail.
Remove the 'rmail-preserve-inbox' line on your main machine, and keep it on your other compters. That way you can check your email when you're away from home, and then you can go home and download them all. (Be sure to have a backup, too!)
Let's make Rmail more fun with a few extra variables and functions!
(setq rmail-default-file "~/.emacs.d/mymail/muto/muto" rmail-mime-prefer-html nil message-signature "Lots of love, -Muto\nhttps://muto.ca" rmail-default-headers "FCC: ~/.emacs.d/mymail/muto/sent") ;; Make a function that opens rmail ;; without checking for new mail! (defun rmail-no-check () (interactive) (rmail-input rmail-default-file)) ;; Shortcut for rmail-no-check (global-set-key "\C-cmc" 'rmail-no-check) ;; Make C-o move between the email & inbox buffers (add-hook 'rmail-summary-mode-hook (lambda () (local-set-key (kbd "C-o") 'other-window))) (add-hook 'rmail-mode-hook (lambda () (local-set-key (kbd "C-o") 'other-window)))
First we set 'rmail-default-file', which sets the default path for rmail to look when you use 'o' to output a file (by default it's ~/xmail, but I set it to my inbox file so I can be in the right directory)
We tell rmail to use plaintext if possible (but use HTML if there is no plaintext option available), Then we add a mail signature (note that escapes like \n are supported)!
Then we set 'rmail-default-headers' to a string that says "When you send an email to someone, also put it in an rmail-readable 'sent' file!"
We also add a shortcut for opening rmail without needing to check every time, and we defined C-o to be 'other-window', because I usually map C-o to other-window, but rmail re-defines it to be the same as 'o', which I don't need!
So, I use more than one email account. I have an email for every website I own, I have a gmail that I have from the stone ages (I can't delete my gmail! It's linked to my Webkinz account!), I have a work email, and I have my main email, so I like to switch between them easily. I can do this with an emacs function!
;; Configure the first email account: (defun mail-skel () (interactive) (setq rmail-primary-inbox-list (list (concat "imaps://skeleton%40muto.ca" ":PA55W0RD" "@mail.gandi.net")) rmail-preserve-inbox t rmail-default-file "~/.emacs.d/mymail/skel/skel" user-mail-address "skeleton@muto.ca" user-full-name "Skeleton" rmail-file-name "~/.emacs.d/mymail/skel/skel" rmail-default-headers "FCC: ~/.emacs.d/mymail/skel/sent") message-signature "Boo! -Skel") (message "%s" (propertize "Email account: Skeleton"))) ;; Configure the second account (defun mail-muto () (interactive) (setq rmail-primary-inbox-list (list (concat "imaps://shack%40muto.ca" ":passw0rd123" "@mail.gandi.net")) rmail-preserve-inbox t rmail-default-file "~/.emacs.d/mymail/muto/muto" user-mail-address "shack@muto.ca" user-full-name "Muto" rmail-file-name "~/.emacs.d/mymail/muto/muto" rmail-default-headers "FCC: ~/.emacs.d/mymail/muto/sent") message-signature "Lots of love! -Muto") (message "%s" (propertize "Email account: Muto"))) ;; Set the default mail account (mail-muto) ;; Keybindings to switch between accounts: (global-set-key "\C-cmm" 'mail-muto) (global-set-key "\C-cms" 'mail-skel)
Looking good! We pretty much just took all the 'setenv' functions, and all our 'setq' declarations, and slapped them inside a function, then copied them all into another function! We also used 'message', which lets us print a minibuffer message telling us which account we just switched to!
You can see videos where I talk about rmail here! :)
If you use rmail and have discovered any way to make it even nicer, or if you're having trouble following or understanding this article, please email me at 'shack at muto.ca'!
Made with Spook! | Source code | Hire me.