Rmail

Rmail is the default mail reader for GNU Emacs. With it you can read multiple local and remote inboxes.

Rmail is the primary Emacs mail-reader. I don't know how many people currently use it, but I will ignore any suggestion to treat it as unimportant.RichardStallman [1]

See GettingMail, WritingMail, and SendingMail for more setup examples.

Configuration

You should download the ‘mailutils’ package on your computer if you want the best rmail experience.

Here is a detailed Rmail configuration. A simpler example is in GettingMail.

(setq
 ;; The mail URL, specifying a remote mail account
 ;; (Omit this to read from /var/mail/user)
 rmail-primary-inbox-list
  '("pop://me%40example.com:Passw0rD@mail.example.com"))

 send-mail-function 'smtpmail-send-it       ; Send mail via SMTP
 rmail-preserve-inbox 1                     ; Don't delete mail from server
 rmail-delete-after-output 1                ; Delete original mail after copying
 rmail-mime-prefer-html nil                 ; Prefer plaintext when possible
 rmail-file-name   "~/mail/inbox"           ; The path to our inbox file
 rmail-secondary-file-directory "~/mail"    ; The path to our other mbox files
 message-default-headers "Fcc: ~/mail/sent" ; Copy sent mail to the "sent" file
 user-full-name    "Susan"                  ; Our full name
 user-mail-address "me@example.com"         ; Our return address
 message-signature "Plop! -S")              ; A signature

You can also decide how rmail handles HTML emails with the ‘shr’ variables:

(setq
 shr-use-fonts nil  ; Don't load fancy fonts
 shr-indentation 2  ; A left-margin of 2 columns
 shr-use-colors nil ; Don't load special colors
 shr-width 70       ; Fix width to 70 columns
 shr-bullet "• ")   ; A bullet character for <li> elements

Note that the ‘shr’ variables also apply to eww

Basic Usage

Start rmail with ‘M-x rmail’. With no configuration, this attempts to move all your mail from your local spool file to the Rmail primary file pointed by ‘rmail-file-name’ (defaults to ~/RMAIL)

Some helpful keys:

Reading mail

You can tell how many messages you want to appear in the summary buffer with ‘rmail-summary-window-size’.

Mailing lists

Use the handy command ‘M-x undigestify-rmail-message’ when viewing a mailing list digest to split it into separate messages. The original message is marked for deletion.

Writing mail

To start writing a new message, you can use ‘C-x m’ or ‘M-x mail’ from anywhere in Emacs.

If you are in an rmail buffer, just press ‘m’ to create a new mail, ‘r’ to reply to a message, or ‘f’ to forward a message.

By default, rmail uses MailMode for composition. You can change this by setting the ‘mail-user-agent’ variable:

;; Use Mail mode to compose messages (default)
(setq mail-user-agent 'sendmail-user-agent)

;; To use Message mode instead:
(setq mail-user-agent 'message-user-agent)

Sending Mail

When writing a message in mail mode, you can send it with C-c C-s.

If you want to use msmtp (or another MTA) to handle sending, you can set the following variables like so:

(setq
  message-send-mail-function 'message-send-mail-with-sendmail
  sendmail-program "/usr/bin/msmtp")

Sorting mail

The two major sorting methods in rmail are labels and files.

Labels (tags)

You can add one or more labels to a message. You can also filter your inbox to only display certain labels.

Output files

You can move your mail from the inbox into different mbox files (like “family”, “work”, etc). These mbox files behave exactly the same as the inbox.

The variable ‘rmail-output-file-alist’ lets you set default files for specified email addresses, so you don’t have to type the name of the file each time you press ‘o’. If you set ‘rmail-automatic-folder-directives’, filing happens automatically after the mail is received from the inbox.

Attachments & non-ASCII mail

You can display attachments using RmailMime.

Non-ASCII mails often use “encoded-words” as specified in RFC 2047. Here’s how to use rfc2047.el that comes with Emacs:

(autoload 'rfc2047-decode-string "rfc2047")
(autoload 'rfc2047-decode-region "rfc2047")
(setq rmail-message-filter
      (lambda ()
        (save-excursion
          (when (search-forward "\n\n" nil t)
            (rfc2047-decode-region
              (point-min) (match-beginning 0)))))
      rmail-summary-line-decoder
      (function rfc2047-decode-string))

[MDL: The above only works for summary lines in Emacs 23 because rmail-message-filter is no longer used. Anyone have a fix for this?]

Editing message text and headers

Pressing ‘e’ in an rmail buffer puts you in editing mode. If you accidentally got there, press `C-c C-]’ to abort. Otherwise, make your changes, then press ‘C-c C-c’ to save them and return to reading mode.

Helpful Libraries

Other Formats

Rmail supports mboxo files. It does not have support for maildir, mh, mboxd, or other formats. Rmail can convert Babyl files to mboxo, though.

Rmail used to store mail in a Babyl file. As of Emacs 23, rmail uses a standard mbox format: mboxo. mboxo performs some irreversible conversions such as replacing From in the body of a mail with >From if it occurs at the start of a line. For most people this is unimportant.

Prior to Emacs 23, rmail used the babyl file format. Rmail will automatically convert babyl to mbox, but you can also use ‘M-x unrmail’ or the command-line b2m utility.

Encryption

You can enable TLS encryption by setting ‘rmail-movemail-flags’:

(setq rmail-movemail-flags "--tls")

Another possible method is by using Stunnel.

External Links


CategoryMail