103

How can we use emacs to read and write email?

This question is intended to provide a canonical landing point for users wanting to deal with email using emacs.

Please post only one package/solution per answer, with as much details as you can. Information that may be useful include:

  • requirements, supported environment
  • supported methods (read and/or send)
  • supported protocols (pop, imap, smtp, local mail setup...)
  • supported authentications
  • password storage (none, plain-text, access to an external wallet...)
  • offline support (none, aggressive caching, on-demand...)
  • how easy is it to use attachements? (adding with drag-and-drop, downloading, opening with emacs or another application...)
  • setup instructions (the more detailed the better), screenshots...
  • support for additional email features (archiving, filtering, folders)
  • support for additional related features (contacts, rss feeds)... no need to be too detailed here, depending on how closely the feature relates to email

Solutions requiring an external tool in order to process the mail are welcome, as long as the user does not need to interact directly with the external process.

Examples: a package acting as a front-end for mutt is on-topic, a solution allowing a thunderbird user to write his message using emacs isn't.

Meta post for discussion.

Quick links to answers (alphabetically):

5
  • 3
    Is there a way to read email with emacs supporting drag and drop to add attachment? This is the feature that really simplifies the life with an email client.
    – Name
    Commented Jun 6, 2015 at 10:26
  • 1
    @Name does Emacs even support drag and drop?
    – PythonNut
    Commented Jun 19, 2015 at 15:49
  • @PythonNut well, if I drag and drop a file on a buffer, Emacs opens that file. So it seems that in principle Emacs can handle drag and drop calls from the system.
    – Name
    Commented Jun 19, 2015 at 16:16
  • @PythonNut Yes, Emacs does support DnD. See here and here.
    – Basil
    Commented Oct 4, 2017 at 12:50
  • @Name: I find using helm or ivy to pick attachments much easier than dragging and dropping them, but that's a matter of personal preference.
    – Omar
    Commented Oct 7, 2017 at 3:13

6 Answers 6

48

I use Mu4e. It is well documented (also via Info), and as of this writing, actively developed.

Mu4e is shipped as an add-on to mu, "a set of tools to deal with Maildirs and message files, in particular to index and search e-mail messages". It works together with offlineimap or fetchmail. I also use the Emacs package smtpmail-multi so that I can send from different accounts with different settings. For smooth integration with your email provider, you should apt-get install ca-certificates. And if you want a package-managed version, you can grab mu itself with apt-get install maildir-utils.

Several example configurations are supplied, including the following "minimal configuration":

(require 'mu4e)     
(setq message-send-mail-function   'smtpmail-send-it
      smtpmail-default-smtp-server "smtp.example.com"
      smtpmail-smtp-server         "smtp.example.com"
      smtpmail-local-domain        "example.com")

Depinding on the set-up of your mail provider, you will need to do a bit more; and in particular, you will need to configure OfflineIMAP or Fetchmail to actually retrieve the mail. In my configuration, shown below, I set everything up to work with two accounts. If you just need to retrieve from one account, you may want to refer to the sample .offlineimaprc included in the mu4e manual.

As for extensions and integration with other Emacs packages: Mu4e integrates conveniently with Org Mode (for capturing links to messages or custom searches, and even for authoring HTML formatted emails using Org syntax, although I don't use that feature) via the included org-mu4e.el. There is a separate helm-mu integration that is usable, but needs some more work IMO. It is themed in solarized.el. There is also a mu4e-maildirs-extension that gives a convenient count of read and unread messages per mail directory, and there is some other stuff I haven't tried.

Together with the docs, these sample configs may help a new mu4e user get off the ground.

.offlineimaprc

[general]
accounts = Gmail, Uni
maxsyncaccounts = 3

[Account Gmail]
localrepository = Local
remoterepository = Remote
status_backend = sqlite

[Repository Local]
type = Maildir
localfolders = ~/Maildir/google

[Repository Remote]
type = IMAP
remotehost = imap.gmail.com
remoteuser = [email protected]
remotepass = TryAndGuess12345
ssl = yes
maxconnections = 1
realdelete = no

# cert_fingerprint = fa88366ccd90cd02f7a5655800226c43c8044ada
# but they change all the time, so...
sslcacertfile = /etc/ssl/certs/ca-certificates.crt

# Folders to get:
#
# In Gmail, filter all current mail that isn't *otherwise*
# filtered into the folder or folders you want to receive/sync.
# Keep that up to date; it will boost efficiency if you would
# otherwise be syncing a very large "Inbox" here.
folderfilter = lambda foldername: foldername in [
             'JUNE2015', 'Drafts', 'Sent']

[Account Uni]
localrepository = UniLocal
remoterepository = UniRemote
status_backend = sqlite

[Repository UniLocal]
type = Maildir
localfolders = ~/Maildir/uni

[Repository UniRemote]
type = IMAP
remotehost = pod666.outlook.com
remoteuser = [email protected]
remotepass = TryAndGuess9876
ssl = yes
maxconnections = 1
realdelete = no

sslcacertfile = /etc/ssl/certs/ca-certificates.crt

Config for mu4e and smtpmail-multi:

;;; Replies

(setq message-citation-line-function 'message-insert-formatted-citation-line) 
(setq message-citation-line-format "On %a, %b %d %Y, %f wrote:\n")

;;; smtp

(add-to-list 'load-path "~/smtpmail-multi")
(require 'smtpmail-multi)
(require 'smtpmail)

(setq smtpmail-multi-accounts
      (quote
       ((uni . ("[email protected]"
                 "pod666.outlook.com"
                 587
                 "[email protected]"
                 nil nil nil nil))
        (gmail . ("[email protected]"
                   "smtp.gmail.com"
                   587
                   "[email protected]"
                   starttls
                   nil nil nil)))))

(setq smtpmail-multi-associations
      (quote
       (("[email protected]" gmail)
        ("[email protected]" uni))))

(setq smtpmail-multi-default-account (quote gmail))

(setq message-send-mail-function 'smtpmail-multi-send-it)

(setq smtpmail-debug-info t)
(setq smtpmail-debug-verbose t)

;;; MU4E config

(require 'shr)

(defun shr-render-current-buffer ()
  (shr-render-region (point-min) (point-max)))

(setq mu4e-compose-dont-reply-to-self t)
(setq mu4e-compose-signature-auto-include nil)
(setq mu4e-html2text-command 'shr-render-current-buffer)

(setq mu4e-mu-binary "~/mu/mu/mu")

(setq user-full-name "Hello World")
(setq user-mail-address "[email protected]")

(setq mu4e-hide-index-messages t)

(setq
   mu4e-maildir       "~/Maildir"   ;; top-level Maildir
   mu4e-sent-folder   "/sent"       ;; folder for sent messages
   mu4e-drafts-folder "/drafts"     ;; unfinished messages
   mu4e-trash-folder  "/trash"      ;; trashed messages
   mu4e-refile-folder "/archive")   ;; saved messages

(setq
   mu4e-get-mail-command "offlineimap"   ;;  -a Uni to just do university acc't
   mu4e-update-interval nil)             ;; 300 to update every 5 minutes

(setq mu4e-bookmarks
  '( ("flag:unread AND NOT flag:trashed"                "Unread messages"        ?u)
     ("date:today..now"                                 "Today's messages"       ?t)
     ("date:7d..now"                                    "Last 7 days"            ?w)
     ("date:1d..now AND NOT list:emacs-orgmode.gnu.org" "Last 1 days"            ?o)
     ("date:1d..now AND list:emacs-orgmode.gnu.org"     "Last 1 days (org mode)" ?m)
     ("maildir:/sent"                                   "sent"                   ?s)
     ("maildir:/uni/INBOX AND date:7d..now"             "University Last 7 days" ?g)
     ("maildir:/google/JUNE2015 AND date:7d..now"       "Gmail Last 7 days"      ?c)
     ("mime:image/*"                                    "Messages with images"   ?p)))

(setq mu4e-maildir-shortcuts
      '( ("/google/JUNE2015" . ?c)
         ("/uni/INBOX"       . ?g)
         ("/sent"            . ?s)))

(setq mu4e-user-mail-address-list (list "[email protected]" "[email protected]"))

(setq message-kill-buffer-on-exit t)

(setq
 mu4e-view-show-images t
 mu4e-view-image-max-width 800)

;; A little demo function for switching accounts
(defun switch ()
  (interactive)
  (save-excursion (goto-char (point-min))
                  (forward-char 19)
                  (cond
                   ((looking-at "[email protected]")
                    (delete-region (match-beginning 0) (match-end 0))
                    (insert "[email protected]")
                    (buffer-face-set 'default))
                   ((looking-at "[email protected]")
                    (delete-region (match-beginning 0) (match-end 0))
                    (insert "[email protected]")
                    (buffer-face-set 'bold-italic))
                   (t nil))))

(add-hook 'mu4e-compose-mode-hook (lambda () (buffer-face-set 'bold-italic)))

;;; Saving outgoing mail

;; Following tip from documentation for `mu4e-sent-messages-behavior' - see also
;; http://www.djcbsoftware.nl/code/mu/mu4e/Saving-outgoing-messages.html
;; for some related points, but not necessary to do things both ways.

(setq message-sendmail-envelope-from 'header)

(setq mu4e-sent-messages-behavior
      (lambda ()
    (if (string= (message-sendmail-envelope-from) "[email protected]")
        (progn (message "Delete sent mail.")
           'delete)
      (progn (message "Save sent mail.")
         'sent))))

;;; Org mode compatibility

;; Use `org-store-link' to store links, and `org-insert-link' to paste them

(require 'org-mu4e)

;;; That's all

(provide 'my-mu4e-config)

screenshot: browsing with search term list:emacs-orgmode.gnu.org

browsing the org list

15
  • 1
    Does it support Windows emacs?
    – Leu_Grady
    Commented Jun 6, 2015 at 6:52
  • 1
    @user3173715, OfflineIMAP does not officially support Windows "but some have made it work"; Fetchmail is another option and is part of this Unixmail for Windows port; mu itself is "written in C and a bit of C++ (to interface with Xapian)", which has "two options for native Microsoft Windows support." If you're comfortable putting together bits and pieces of code like that, you can, quite likely, get it working. I'm not a Windows user myself so I can't tell you more, maybe someone else would comment further on that. Commented Jun 6, 2015 at 12:24
  • 2
    Is there some website explaining why a gnus-user would want to switch or has switched to mu4e and why ? I'm curious, it seems popular at the moment.
    – politza
    Commented Jun 7, 2015 at 20:41
  • 2
    @Malabarba, I added the "minimal configuration" from the mu4e docs, and linked to their simple example of an .offlineimaprc. Commented Jun 9, 2015 at 21:39
  • 3
    An important feature or deal-breaker, depending upon how a user may see it, is that the mu server runs all the time after launching mu4e and this dramatically affects Emacs performance in my testing and prevents using other utilities such as opening another buffer that needs to use aspell. Communicating with the mu server is a baked-in feature and it is not something that can be disabled. In my opinion, it is a design flaw that should have been corrected with individual calls to mu without running a server 24/7. To verify, type M-x list-processes after running M-x mu4e
    – lawlist
    Commented Jun 14, 2016 at 15:20
29

If you use Gnus (bundled with Emacs already), check https://github.com/redguardtoo/mastering-emacs-in-one-year-guide/blob/master/gnus-guide-en.org

Here is the summary of the guide:

  • Use minimum setup from EmacsWiki is enough (http://www.emacswiki.org/emacs/GnusGmail). It's setup for any mail service, not only Gmail
  • You can read/write html mail
  • You need subscribe mail folders manually
  • Press C-u Enter on any mail folder to see ALL items in that folder, or else, only unread mails are visible
  • popular protocols and authentication methods are supported out of box
  • for password storage, I just used easygpg which is bundled with Emacs. easygpg is a general framework. So the password is encrypted and stored offline.
  • email offline local cache is supported in Gnus ages ago
  • add/remove/download attachments is easy. I don't know the drag-and-drop thing because I only use keyboard. You need setup 'mailcap-mime-data` to open attachment with 3rd party applications.
  • mail searching locally/remotely is supported out of the box
  • filter/archive is supported. But I suggest popfile which is an independent mail filter software. I use popfile because it's much much better than any other mail filter (Gmail's own filter, for example).
  • Contacts management is handled by bbdb (another Emacs plugin), it's also easy to import contacts from Gmail by using gmail2bbdb.el (written by me).
  • For rss reading, you'd better use elfeed (Gnus supports rss by using Gwene service. But elfeed is easier to set up). Gwene is powerful but requires much more knowledge (my Gnus guide, APIs of emacs-w3m, hydra, Lisp programming, Linux cli tools, shell)
  • Gnus supports all platforms. But on Windows, you need add binary from OpenSSH and GnuTLS to your environment variable PATH. These two packages could be installed through Cygwin. Emacs could be Windows native version. Please note since Emacs 26, all dependencies are packaged into one bundle on Windows.

Check my guide for more tips.

IMO, you'd better not replace Gmail's web UI (or any other mail service's web UI) with Gnus completely. The best practice to master Gnus is treating Gnus as an enhancement of Gmail. So you won't get frustrated if Gnus can's do certain thing because you always can fallback on web UI.

Screenshot:

enter image description here

2
  • 4
    Thanks for adding gnus to the list, it appears to be one of the canonical ways of using email with emacs. But at the moment, this answer is only barely more than a link-only answer. It would be more useful to extract information from that link (or elsewhere!) to answer the question more precisely: besides preventing link rotting, it would also help in the comparison with other mail packages.
    – T. Verron
    Commented Jun 18, 2015 at 6:05
  • Also, a screenshot would be great so that new visitors can easily get a sense of the look and feel. Commented Jun 18, 2015 at 10:42
14

Notmuch

I use notmuch for my emails in emacs.

screenshot of the notmuch-hello view

It does only operate on local mails which needed to be stored one message per file and I use maildir folders to which my smtp-server delivers. It should be able to cope with other solutions syncing mails to maildir folders on your computer.

To start using it you install the command-line base and the emacs interface and start configuring via a short text wizard by calling notmuch, setup a regular call to a filtering script which calls notmuch new and tags other mails from the threads you tagged (for example mailing list threads you wish to ignore) or tag mails sorted by your mail daemon into special maildirs. In emacs you call M-x notmuch to see the interface from before. Almost all configuration for the interface can be done via the Customization interface from emacs.

As it doesn't download messages from other systems it has no authentication or protocols built-in, apart from using emacs built-in support for sending emails.

It doesn't use folders as such, but in practice stored searches feel like them for reading mails. It does list all used tags on the notmuch-hello view, so that when you decide how to tag your mail your lists get automatically updated. It doesn't need archiving as it shouldn't slow down when you have a lot of emails.

The elisp part of notmuch brings apart from fast full-text and tagged and scoped searches possibilities to list matches and answer to messages. I don't know how drag and drop would work with notmuch as I use it via terminals and remote shells on my server.

Message view within a thread of messages

alternate tree view of search results

more screenshots: https://notmuchmail.org/screenshots/

The most difficult part about it would be having a synchronized tags when you use notmuch on 2 different computers, but people have worked around that, and from what I gathered from the mailing list it probably works now. Or have a look at https://notmuchmail.org/remoteusage/ for a new setup I just stumbled upon.

There are packages for most linux distributions and it is developed in a bazaar environment via the mailing list. If you self-compile from tarballs or the git, it uses C code and has a dependencies on Xapian for storing the excerpts from the messages, GMime for decoding MIME emails, Talloc for memory management and zlib (which is also a dependency of Xapian).

It would probably function well with rss2email or any solution converting rss feeds into maildirs.

It's usable via the command-line and apart from the default emacs elisp interface other people use it with mutt (copies/hardlinks search results to a maildir folder on the disk) or vim.

It will probably need some maintenance to keep running if your mail volume exceeds mine (~90k messages, not much mail).

1
7

I was a happy user of mew for many years.

I haven't used emacs for reading and writing mail for a long time now, so this information may well be outdated. Hopefully, more recent mew users can fill it in. For now, consider this answer a stub. (I'll make it community wiki, so others can edit it more freely.)

First and foremost, in my experience, mew was fast. I had no difficulty handling mailing lists with enormous traffic using mew.

Setting up mew was a bit involved, especially as it uses (used?) stunnel for creating encrypted connections to SMTP and IMAP servers. But basically, it just involves editing a file ~/.mew.el and setting up a directory for mew to keep its data in. Apart from stunnel (and emacs, of course), it has no dependencies.

The documentation seems adequate, though I often found myself looking in the wrong section. Maintenance seems to have slowed to a trickle, though. There are some bug fixes now and then, but no new features that I have noticed for a while.

3
  • I'd provide more detail, but as I said, I haven't used emacs for mail for a long time. Primarily because of the deluge of HTML-only formatted email, which became a major pain in the posterior in the long run. So these days, I only use GUI based email clients. Commented Apr 9, 2016 at 16:23
  • Thank you for listing it, hopefully some other mew user can come in and fill the blanks. About html-formatted e-mails, maybe the situation has changed generally now that emacs ships with an html renderer?
    – T. Verron
    Commented Apr 10, 2016 at 7:36
  • @T.Verron Could be. I'm pretty sure that mew does not support the built-in html renderer out of the box. A big question, though, is how to deal with inline images? If they're links to external images, no problem, but what about images included with the message? BTW, it can be configured to show HTML-coded mail using w3m, but I never got around to testing that. Commented Apr 10, 2016 at 7:44
7

WANDERLUST: https://github.com/wanderlust/wanderlust

FEATURES:

  • Implementation in elisp only.
  • Support of IMAP4rev1, NNTP, POP(POP3/APOP), MH and Maildir.
  • Integrated access to messages based on Folder Specifications like Mew.
  • Key bindings and mark processing like Mew.
  • Management of threads and unread messages.
  • Folder mode to select and edit subscribed folders.
  • Message cache, Disconnected Operation.
  • MH-like Fcc (Fcc: %Backup is possible).
  • Full support of MIME (by SEMI).
  • Draft editing of mail and news as a same interface.
  • Icon based interface for the list of Folder (XEmacs and >= Emacs 21).
  • Skip fetching of a large message part of MIME(IMAP4).
  • Server side searching (IMAP4), internationalized searching is available.
  • Virtual folder, including, but not limited custom searches using Wanderlust, or external utilities such as mu and grep.
  • Compressed folder.
  • Automatic expiration of old messages.
  • Automatic refiling.
  • Draft templates.

EMACS WIKI: https://www.emacswiki.org/emacs/WanderLust

1

I use mutt for day-to-day email management. However, when there is a need to leverage the text manipulation functionality that Emacs provides, I read email using https://github.com/nicferrier/emacs-maildir .

  • Requirements, supported environment:

Email must be stored in the maildir format. As my email is already in a local maildir (I use fdm to fetch), all that is needed is:

;; Specify the location of the maildir directory
> (setq maildir-mail-dir "/home/me/mail/my-fdm-maildir/")

and

M-x maildir-list.

  • How easy is it to use attachments?

Use the > key from the message-view mode to view attachments.

  • Support for additional email features (archiving, filtering, folders):

Unknown.

  • Support for additional related features (contacts, rss feeds):

I don't believe this package provides support for these sorts of things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.