Gmail is a popular e-mail provider; let’s see how we can make it
work with mu4e
. Since we are using IMAP, you must enable that
in the Gmail web interface (in the settings, under the “Forwarding and
POP/IMAP”-tab).
Gmail users may also be interested in Including related messages, and in Skipping duplicates.
First of all, we need a program to get the e-mail from Gmail to our
local machine; for this we use offlineimap
; on Debian (and
derivatives like Ubuntu), this is as easy as:
$ sudo apt-get install offlineimap
while on Fedora (and similar) you need:
$ sudo yum install offlineimap
Then, we can configure offlineimap
by editing ~/.offlineimaprc:
[general] accounts = Gmail maxsyncaccounts = 3 [Account Gmail] localrepository = Local remoterepository = Remote [Repository Local] type = Maildir localfolders = ~/Maildir [Repository Remote] type = IMAP remotehost = imap.gmail.com remoteuser = USERNAME@gmail.com remotepass = PASSWORD ssl = yes maxconnections = 1
Obviously, you need to replace USERNAME
and PASSWORD
with your actual
Gmail username and password. After this, you should be able to download your
mail:
$ offlineimap OfflineIMAP 6.3.4 Copyright 2002-2011 John Goerzen & contributors. Licensed under the GNU GPL v2+ (v2 or any later version). Account sync Gmail: ***** Processing account Gmail Copying folder structure from IMAP to Maildir Establishing connection to imap.gmail.com:993. Folder sync [Gmail]: Syncing INBOX: IMAP -> Maildir Syncing [Gmail]/All Mail: IMAP -> Maildir Syncing [Gmail]/Drafts: IMAP -> Maildir Syncing [Gmail]/Sent Mail: IMAP -> Maildir Syncing [Gmail]/Spam: IMAP -> Maildir Syncing [Gmail]/Starred: IMAP -> Maildir Syncing [Gmail]/Trash: IMAP -> Maildir Account sync Gmail: ***** Finished processing account Gmail
We can now run mu
to make sure things work:
$ mu index mu: indexing messages under /home/foo/Maildir [/home/foo/.cache/mu/xapian] | processing mail; checked: 520; updated/new: 520, cleaned-up: 0 mu: elapsed: 3 second(s), ~ 173 msg/s mu: cleaning up messages [/home/foo/.cache/mu/xapian] / processing mail; checked: 520; updated/new: 0, cleaned-up: 0 mu: elapsed: 0 second(s)
We can run both the offlineimap
and the mu index
from within
mu4e
, but running it from the command line makes it a bit easier to
troubleshoot as we are setting things up.
Note: when using encryption, you probably do not want to
synchronize your Drafts-folder, since it contains the unencrypted
messages. You can use OfflineIMAP’s folderfilter
for that.
Next step: let’s make a mu4e
configuration for this:
(require 'mu4e) ;; use mu4e for e-mail in emacs (setq mail-user-agent 'mu4e-user-agent) (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 takes care of this (setq mu4e-sent-messages-behavior 'delete) ;; (See the documentation for `mu4e-sent-messages-behavior' if you have ;; additional non-Gmail addresses and want assign them different ;; behavior.) ;; setup some handy shortcuts ;; you can quickly switch to your Inbox -- press ``ji'' ;; then, when you want archive some messages, move them to ;; the 'All Mail' folder by pressing ``ma''. (setq mu4e-maildir-shortcuts '( (:maildir "/INBOX" :key ?i) (:maildir "/[Gmail].Sent Mail" :key ?s) (:maildir "/[Gmail].Trash" :key ?t) (:maildir "/[Gmail].All Mail" :key ?a))) (add-to-list 'mu4e-bookmarks ;; ':favorite t' i.e, use this one for the modeline '(:query "maildir:/inbox" :name "Inbox" :key ?i :favorite t)) ;; allow for updating mail using 'U' in the main view: (setq mu4e-get-mail-command "offlineimap") ;; something about ourselves (setq user-mail-address "USERNAME@gmail.com" user-full-name "Foo X. Bar" message-signature (concat "Foo X. Bar\n" "http://www.example.com\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 (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 '(("smtp.gmail.com" 587 "USERNAME@gmail.com" nil)) smtpmail-default-smtp-server "smtp.gmail.com" smtpmail-smtp-server "smtp.gmail.com" smtpmail-smtp-service 587) ;; alternatively, for emacs-24 you can use: ;;(setq message-send-mail-function 'smtpmail-send-it ;; smtpmail-stream-type 'starttls ;; smtpmail-default-smtp-server "smtp.gmail.com" ;; smtpmail-smtp-server "smtp.gmail.com" ;; smtpmail-smtp-service 587) ;; don't keep message buffers around (setq message-kill-buffer-on-exit t)
And that’s it — put the above in your emacs initialization file, change
USERNAME
etc. to your own, restart Emacs, and run M-x mu4e.