Actually Using Emacs Rmail
I've used Emacs rmail for 5 years. I have used mutt, notmuch, mu4e, claws, geary, and others, but I have a healthy relationship with rmail and, although I have written short sections on it, I owe it at least one good article, so here we go!
Setting Things Up Right
I'll only talk about getting mail from a remote inbox, since that's what I have.
Here's a complete config for
(setq rmail-primary-inbox-list (list (concat "imaps://bird%40muto.ca" ":Passw0rD" "@mail.muto.ca")) send-mail-function 'smtpmail-send-it rmail-preserve-inbox 1 rmail-delete-after-output 1 rmail-mime-prefer-html nil rmail-file-name "/var/mail/bird" rmail-secondary-file-directory "~/mail" message-default-headers "Fcc: ~/mail/sent" user-full-name "Bird" user-mail-address "email@example.com" message-signature "Chirp! -Bird")
Looks good! Here's what these variables do:
rmail-primary-inbox-list specifies a remote mailbox using this format:
I cut it to multiple lines for readability using
%40 is a
URL code for
@. This is how Mailutils works. It's not bad, but it's awkward at first.
Then we set some variables:
- Use the
smtp-mail-send-itfunction to send email.
rmail-preserve-inboxmeans "copy mail from the server, don't delete it!"
rmail-delete-after-output- after copying mail to another file, delete the original.
rmail-mime-prefer-html- use plaintext when possible
rmail-file-nameis where we want our mail to go.
rmail-secondary-file-nameis a folder where we organize our mail into seperate files.
message-default-headerslets us add headers. In this case, when we send an email, a copy of the mail goes into
user-full-namesets our name.
user-mail-addresssets our "return to" address.
message-signatureputs some text at the end of each email.
Looks good so far! Let's test it out to make sure it works.
Start rmail with
M-x rmail. Use
h to view your inbox, and
g to attempt to get new mail.
Send an email with
m to whoever you want, and that should be it! In the inbox summary view you can use
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 file with
o, it appends it to a file that behaves the same as your inbox file, so you can sort your mail into different files. I have files named
note to sort between conversational emails and notification/junk emails! It's nice.
The Tickets File
Previously, we stored our password in
init.el. That's not very cool, is it?
Mailutils comes with something called a "Ticket File", a file at
~/.mu-tickets that holds mail account information, like so:
# ~/.mu-tickets # The Ticket file has one mail URL per line. imaps://bird%40muto.ca:Passw0rd@mail.muto.ca imaps://skel%40muto.ca:firstname.lastname@example.org
Now you can remove the password section in your
init.el file like so:
(setq rmail-primary-inbox-list '("imaps://email@example.com"))
Don't Keep Your Mail On the Server!
Quick PSA, download your email and store them locally. If you set
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.
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.
Some Advanced Configuration
Let's make Rmail more fun with a few extra variables and functions!
;; Open 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)))
The Mailrc file
When you write an email, you have to write the recipient's address in the
TO: field. That's fine, but what's more fine is the ability to create aliases for all your contacts!
Create the file
~/.mailrc and write something like this in it:
alias bird "Bird <firstname.lastname@example.org>" alias skel "Skeleton <email@example.com>" alias example "Another Friend <firstname.lastname@example.org>"
.mailrc file can define shortcuts that allow you to tab-complete your contacts in
Now, when you're writing an email, if you want to write an email to Bird, you would put
bird in the
TO: field, then press
TAB, which would expand it to say
The mailrc file also acts as a contact list. It's just… It's…. Gosh it's handy!
I have more than one email account. Here's a config that lets you use multiple accounts!
;; Configure the first email account: (defun mail-skel () (interactive) (setq rmail-primary-inbox-list '("imaps://email@example.com") user-full-name "Skeleton" user-mail-address "firstname.lastname@example.org" rmail-file-name "~/mail/skel/inbox" message-default-headers "FCC: ~/mail/skel/sent") (message "%s" (propertize "Email account: Skeleton"))) ;; Configure the second account (defun mail-bird () (interactive) (setq rmail-primary-inbox-list '("imaps://email@example.com") user-full-name "Bird" user-mail-address "firstname.lastname@example.org" rmail-file-name "~/mail/bird/inbox" message-default-headers "FCC: ~/mail/bird/sent") (message "%s" (propertize "Email account: Bird"))) ;; Set the default mail account (mail-bird) ;; Keybindings to switch between accounts (global-set-key "\C-cmm" 'mail-bird) (global-set-key "\C-cms" 'mail-skel)
Looking good! We pretty much just took a bunch
setq declarations, 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!