Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Manage your email in emacs with mu4e

Manage your gmail account in emacs with mu4e

There're a lot of combinations to manage your email with emacs, but this works for me. I've a backup and I can manage my daily email.

The stack:

  • emacs
  • offlineimap
  • mu
  • mu4e



$ pacman -S offlineimap



accounts = Gmail
maxsyncaccounts = 1
pythonfile = ~/

[Account Gmail]
localrepository = Local
remoterepository = Remote

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

[Repository Remote]
type = Gmail
remoteuser =
remotepasseval = get_password_emacs("", "", "993")
realdelete = no

folderfilter = lambda foldername: foldername not in ['[Gmail]/Spam', '[Gmail]/All Mail', '[Gmail]/Starred', '[Gmail]/Important']

holdconnectionopen = true
keepalive = 60
sslcacertfile = /etc/ssl/certs/ca-certificates.crt


import re, os

def get_password_emacs(machine, login, port):
    s = "machine %s login %s port %s password ([^ ]*)\n" % (machine, login, port)
    p = re.compile(s)
    authinfo = os.popen("gpg -q --no-tty -d ~/.authinfo.gpg").read()


machine login port 993 password blabla123bla456
machine login port 587 password blabla123bla456

With emacs, to encrypt this file:

  • M-x epa-encrypt-file (generate ~/.authinfo.gpg and remove original).


$ offlineimap (here you can take a beer).



$ yaourt -S mu


$ mu index --maildir=~/Maildir


mu4e is installed by default with mu package. Only that you needs is load it in emacs.


in your .emacs, ~/emacs.d/init.el or whatever.


  • To send mails with smtpmail.el and use gnutls, we need install the package (pacman -S gnutls)
(require 'mu4e)

;; default
(setq mu4e-maildir (expand-file-name "~/Maildir"))

(setq mu4e-drafts-folder "/[Gmail].Drafts")
(setq mu4e-sent-folder   "/[Gmail].Sent Mail")
(setq mu4e-trash-folder  "/[Gmail].Trash")

;; don't save message to Sent Messages, GMail/IMAP will take care of this
(setq mu4e-sent-messages-behavior 'delete)

;; setup some handy shortcuts
(setq mu4e-maildir-shortcuts
      '(("/INBOX"             . ?i)
        ("/[Gmail].Sent Mail" . ?s)
        ("/[Gmail].Trash"     . ?t)))

;; allow for updating mail using 'U' in the main view:
(setq mu4e-get-mail-command "offlineimap")

;; something about ourselves
;; I don't use a signature...
 user-mail-address ""
 user-full-name  "Toni Reina"
 ;; message-signature
 ;;  (concat
 ;;    "Foo X. Bar\n"
 ;;    "\n")

;; sending mail -- replace USERNAME with your gmail username
;; also, make sure the gnutls command line utils are installed
;; package 'gnutls-bin' in Debian/Ubuntu, 'gnutls' in Archlinux.

(require 'smtpmail)

(setq message-send-mail-function 'smtpmail-send-it
      starttls-use-gnutls t
      '(("" 587 nil nil))
      (expand-file-name "~/.authinfo.gpg")
      smtpmail-default-smtp-server ""
      smtpmail-smtp-server ""
      smtpmail-smtp-service 587
      smtpmail-debug-info t)
Copy link

raksugi commented May 30, 2017

@peterwvj Thanks for the tip. That worked for me.

Copy link

Copy link

thanks for the guide! really helpful.
mu index --maildir=~/Maildir does not work as of mu 1.3.8, instead first run:
mu init --maildir=~/Maildir and then mu index

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment