Skip to content

Instantly share code, notes, and snippets.

@even4void
Last active August 21, 2021 08:47
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save even4void/7397629 to your computer and use it in GitHub Desktop.
Save even4void/7397629 to your computer and use it in GitHub Desktop.
Basic setup to use Gmail from Emacs using a combination of mu, mu4e and offlineimap
(require 'offlineimap)
(add-to-list 'load-path "~/.emacs.d/lib/mu4e")
(require 'mu4e)
(require 'mu4e-maildirs-extension)
(mu4e-maildirs-extension)
(setq mu4e-drafts-folder "/drafts"
mu4e-sent-folder "/sent"
mu4e-trash-folder "/trash")
(setq mu4e-maildir-shortcuts
'(("/INBOX" . ?i)
("/sent" . ?s)
("/trash" . ?t)
("/drafts" . ?d)
("/review" . ?r)
("/cours" . ?c)
("/private" . ?p)
("/inserm" . ?m)
("/aphp" . ?a)
("/mailing" . ?l)))
(add-to-list 'mu4e-bookmarks '("flag:attach" "Messages with attachment" ?a) t)
(add-to-list 'mu4e-bookmarks '("size:5M..500M" "Big messages" ?b) t)
(add-to-list 'mu4e-bookmarks '("flag:flagged" "Flagged messages" ?f) t)
(setq mu4e-headers-date-format "%Y-%m-%d %H:%M:%S"
mu4e-headers-fields '((:date . 20)
(:flags . 5)
(:mailing-list . 10)
(:from-or-to . 25)
(:subject . nil)))
(setq mu4e-reply-to-address "xxxxxxxxxx"
user-mail-address "xxxxxxxxxx"
user-full-name "xxxxxxxxxx"
message-signature "xxxxxxxxxx"
message-citation-line-format "On %Y-%m-%d %H:%M:%S, %f wrote:"
message-citation-line-function 'message-insert-formatted-citation-line
mu4e-headers-results-limit 250)
(require 'smtpmail)
(setq message-send-mail-function 'smtpmail-send-it
starttls-use-gnutls t
smtpmail-starttls-credentials
'(("smtp.gmail.com" 587 nil nil))
smtpmail-auth-credentials
(expand-file-name "~/.authinfo.gpg")
smtpmail-default-smtp-server "smtp.gmail.com"
smtpmail-smtp-server "smtp.gmail.com"
smtpmail-smtp-service 587
smtpmail-debug-info t)
(setq message-kill-buffer-on-exit t
mu4e-sent-messages-behavior 'delete
mu4e-headers-skip-duplicates t
mu4e-headers-include-related t
mail-user-agent 'mu4e-user-agent
mu4e-get-mail-command "offlineimap"
mu4e-attachment-dir "~/Downloads"
smtpmail-queue-mail nil
smtpmail-queue-dir "~/Maildir/queue/cur")
[general]
accounts = Gmail
maxsyncaccounts = 3
[Account Gmail]
localrepository = Local
remoterepository = Remote
[Repository Local]
type = Maildir
localfolders = ~/Maildir
folderfilter = lambda foldername: foldername not in ['queue']
nametrans = lambda folder: re.sub('drafts', '[Gmail].Drafts',
re.sub('sent', '[Gmail].Sent Mail',
re.sub('trash', '[Gmail].Trash', folder)))
[Repository Remote]
type = IMAP
remotehost = imap.gmail.com
remoteuser = xxxxxxxxxx
remotepass = xxxxxxxxxx
ssl = yes
maxconnections = 5
realdelete = no
sslcacertfile = /etc/postfix/certs/Equifax_Secure_Certificate_Authority.cer
folderfilter = lambda foldername: foldername not in ['[Gmail]/Spam','[Gmail]/Starred','[Gmail]/All Mail',
'aliquote','StackExchange','genim','ciep','cnrs','ovh','job-ads']
# nametrans = lambda foldername: foldername.replace("[Gmail]/","")
nametrans = lambda folder: re.sub('.*Drafts$', 'drafts',
re.sub('.*Sent Mail$', 'sent',
re.sub('.*Trash$', 'trash', folder)))
@even4void
Copy link
Author

Here are my config files to read/write emails with Emacs on OS X 10.7. It relies on offlineimap to fetch and synchronize data between Gmail and a local Maildir, and the great mu software to quickly index and query a local Maildir. It also includes an emacs-based e-mail client (mu4e). There are many discussion around mu, e.g., Email done right. I was personally looking for a text-based interface: Apple Mail.app, Mailmate, Postbox, or Sparrow are probably great tools. However, if we can stay in Emacs to fetch and process our emails, why not take advantage of this opportunity?

screenshot

Installation instructions (Glib, xapian, GMime, etc.) are provided in a separate post: Using mu to manage e-mails. I also use mu4e-maildirs-extension, which is available from the MELPA repository. Note that regarding authentification, I now rely on Equifax certificates directly. The above settings try to accomodate Gmail departure from standard IMAP convention. I renamed all things like [Gmail]/Sent Mail to more usual folder name (e.g., sent). I don't sync the All Mail folder since all my mails are tagged (only one Gmail label is associated to each mail, though) and should end up in one local directory. Likewise, I don't fetch 'starred' messages, because mu can find them easily. I also discard some other Gmail labels which I only keep for historical reasons.

Caution: Replace xxxxxxxxxx with your user account, password or signature, where appropriate.

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