![[Home]](https://www.emacswiki.org/images/logo218x38.png)
Rmail is the default mail reader for GNU Emacs. With it you can read multiple local and remote inboxes.
See GettingMail, WritingMail, and SendingMail for more setup examples.
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-mail-new-frame 1 ; Compose in a full frame 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
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:
? - Full list of keybindingsn - Next messagep - Previous messaged - Mark current message for deletionu - Unmark current messagex - Delete all marked messagesr - Replym - Compose a new emailo - Output mail to an mbox filei - Open an mbox filea - Add label to current messagel - Filter inbox by labelM-s - Search all mail (also see MairixSearch)‘h’ key makes a list of messages (summary) appear.‘n’ and ‘p’.‘Spacebar’ and ‘Backspace’ to scroll through the current message.You can tell how many messages you want to appear in the summary buffer with ‘rmail-summary-window-size’.
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.
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)
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")
The two major sorting methods in rmail are labels and files.
You can add one or more labels to a message. You can also filter your inbox to only display certain labels.
‘a’ - Add a label, or multiple separated by a comma‘k’ - Remove label‘l’ - Sort by labelYou 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.
‘o’ - Output message to an mbox file‘i’ - Visit an mbox fileThe 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.
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?]
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.
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.
You can enable TLS encryption by setting ‘rmail-movemail-flags’:
(setq rmail-movemail-flags "--tls")
Another possible method is by using Stunnel.
While writing an email, you can use ‘M-x mml-secure-message-sign-encrypt’ (or ‘C-c C-m C-e’) to mark the email for encryption.
When you send the email, it will be encrypted based on the recipient’s email address, if it’s linked to a PGP key.
While reading an encrypted email, you can use ‘M-x rmail-epa-decrypt’ to decrypt the email.
More:
You can use a Mail Retrieval Agent (MRA) other than ‘movemail’ by simply creating a function that calls the command of your choice. This example uses ‘mpop’:
(defun rmail-my-mra () (interactive) (shell-command "echo 'Checking mail...'") (shell-command "mpop --half-quiet") (rmail-summary)) (add-hook 'rmail-mode-hook (lambda () (local-set-key "g" 'rmail-my-mra)))
From here, you can use ‘M-x rmail-my-mra’ or press ‘g’ from an ‘rmail’ buffer, and Emacs will call ‘mpop’ to retrieve your mail.