Muto - Blog - Feed

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 init.el:

  (list (concat "imaps://"

 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 ""
 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 concat. %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-it function to send email.
  • rmail-preserve-inbox means "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-name is where we want our mail to go.
  • rmail-secondary-file-name is a folder where we organize our mail into seperate files.
  • message-default-headers lets us add headers. In this case, when we send an email, a copy of the mail goes into ~/mail/sent
  • user-full-name sets our name.
  • user-mail-address sets our "return to" address.
  • message-signature puts some text at the end of each email.

Looks good so far! Let's test it out to make sure it works.

Using Rmail

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 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 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 conv and 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.


Now you can remove the password section in your init.el file like so:


Don't Keep Your Mail On the Server!

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.

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 ()
  (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 <>"
alias skel    "Skeleton <>"
alias example "Another Friend <>"

The .mailrc file can define shortcuts that allow you to tab-complete your contacts in mail-mode!

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 Bird <>!

The mailrc file also acts as a contact list. It's just… It's…. Gosh it's handy!

Multiple Accounts!

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 ()

   user-full-name    "Skeleton"
   user-mail-address ""
   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 ()

   user-full-name    "Bird"
   user-mail-address ""
   rmail-file-name   "~/mail/bird/inbox"
   message-default-headers "FCC: ~/mail/bird/sent")

  (message "%s" (propertize "Email account: Bird")))

;; Set the default mail account

;; 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!


If you discovered any ways to make rmail even nicer, or if you're having trouble using it, let me know!