Next: , Previous: , Up: Example configurations   [Contents]

B.3 Gmail configuration

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 skipping duplicates.

B.3.1 Setting up offlineimap

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:

accounts = Gmail
maxsyncaccounts = 3

[Account Gmail]
localrepository = Local
remoterepository = Remote

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

[Repository Remote]
type = IMAP
remotehost =
remoteuser =
remotepass = PASSWORD
ssl = yes
maxconnections = 1
realdelete = no

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
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/.mu/xapian]
| processing mail; processed: 520; updated/new: 520, cleaned-up: 0
mu: elapsed: 3 second(s), ~ 173 msg/s
mu: cleaning up messages [/home/foo/.mu/xapian]
/ processing mail; processed: 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.

B.3.2 Settings

Next step: let’s make a mu4e configuration for this:

(require 'mu4e)

;; default
;; (setq mu4e-maildir "~/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 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
    '( ("/INBOX"               . ?i)
       ("/[Gmail].Sent Mail"   . ?s)
       ("/[Gmail].Trash"       . ?t)
       ("/[Gmail].All Mail"    . ?a)))

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

;; something about ourselves
   user-mail-address ""
   user-full-name  "Foo X. Bar"
      "Foo X. Bar\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 '(("" 587 nil nil))
     '(("" 587 "" nil))
   smtpmail-default-smtp-server ""
   smtpmail-smtp-server ""
   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 ""
;;     smtpmail-smtp-server ""
;;     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, change USERNAME etc. to your own, and restart emacs, and run M-x mu4e.

Next: , Previous: , Up: Example configurations   [Contents]