Geek: How to use offlineimap and the dovecot mail server to read your Gmail in Emacs efficiently

  1. Make sure you've set up Postfix or some other mail server that can send mail. I'm not going to cover that because my configuration for outgoing mail doesn't use Gmail.
  2. Install dovecot (IMAP server) and offlineimap (IMAP synchronization). You can probably find binaries for your distribution.
  3. Edit /etc/dovecot.conf and set the following:
    default_mail_env = maildir:%h/Maildir
  4. Put the following in ~/.offlineimaprc, changing your_local_username, your_username, and your_gmail_password:
    [general]
    accounts = Gmail
    maxsyncaccounts = 1
    
    [Account Gmail]
    localrepository = Local
    remoterepository = Remote
    
    [Repository Local]
    type = IMAP
    remotehost = localhost
    port = 143
    remoteuser = your_local_username
    
    [Repository Remote]
    type = IMAP
    remotehost = imap.gmail.com
    remoteuser = your_username@gmail.com
    remotepass = your_gmail_password
    ssl = yes
    maxconnections = 1
    realdelete = no
    folderfilter = lambda foldername: foldername in ['INBOX']
    

    If you feel comfortable specifying your password for your local account in your ~/.offlineimaprc, you can do so by adding a remotepass line under the remoteuser line in the [Repository Local] section.

  5. chmod go-rwx ~/.offlineimaprc for a little bit of safety.
  6. Type offlineimap to start synchronizing.
  7. While that's synchronizing, use something like this as your ~/.gnus:
    (setq gnus-select-method
          '(nnimap "Mail"
    	       (nnimap-address "localhost")
    	       (nnimap-stream network)
    	       (nnimap-authenticator login)))
    
    (setq user-mail-address "youremail@example.com")
    (setq gnus-ignored-from-addresses "youruser")
    
  8. Start Emacs. Start Gnus with M-x gnus. If you don't see the INBOX group, press ^ (gnus-group-enter-server-mode), open nnimap:Mail, move your cursor to the INBOX, and either press RET to go into the group or press u (gnus-browse-unsubscribe-current-group) to toggle the subscription status until you're subscribed to the group. Then it should show up on the group screen (M-x gnus).
  9. Hope that helps. Have fun!

Technorati Tags: , , , , ,

Save to - del.icio.us - Digg it - reddit - StumbleUpon

RSS feed | Trackback URI

12 Comments »

This is what I've been looking for! Now everything works perfectly. Thank you very much Sacha

You're welcome! I'm glad it works for you.

 
 

I recently created a very similar setup. I also use the following to start offlineimap from within emacs.


(define-key gnus-group-mode-map (kbd "vo")
'(lambda ()
(interactive)
(shell-command "offlineimap&" "*offlineimap*" nil)))

 

Why not just use a local Maildir folder instead of having to set up an IMAP server? I do something similar but just point my MUA at ~/Maildir

I believe this has something to do with gnus and large Maildir directories. I recall reading that this can be bad.

i'm writing a maildir mode for gnus that can work off the straight mailfolders. i'll post it here when its done.

-hhh

(Comments wont nest below this level)
 
 
 

Thanks Sacha. I'd recently got offlineimap and dovecot out of darwinports for exactly this purpose, but had not got around to the setup. I'll try sorting this out when I get home today.

 

This was very helpful. Since you are not using gmail's smtp server I assume you are not relying on gmail to save copies of your sent mail. So, how are you keeping copies of your sent items. I'm using gnus with dovecot on a local machine and I'm having a devil of a time getting anythign I send to be save locally. All I can get working, by using gcc-self, is a copy in my INBOX rather then in my Sent Items.

 

Looks like the dovecot configuration has changed a bit in recent versions (I'm using version 1.0.10)

The config file is now /etc/dovecot/dovecot.conf

The default_mail_env option is now called mail_location.

 

offlineimap supports the 'Gmail' type, so you don't need all that extra fluff (ssl, the host, maxconnections etc).

Also, I like to add

folderfilter = lambda foldername: foldername not in ['[Gmail]/All Mail']

Cheers

 

This looks really neat…I've been trying to move away from Thunderbird to Emacs + gnus + bbdb for my email, so this is very useful.

One problem I'm having though…After offlineimap synchronizes and dovecot is running, I can't seem to actually see the group. I do M-x gnus, ^ to the groups buffer, but when I try to select the nnimap:Mail group, it just says "nnimap: Generating active list for Mail…" forever (that is, until Emacs freezes).

Oddly enough, if I hit C-g at just the right time, I can see the list of folders/labels, but that only works occasionally.

If I access the dovecot server with Thunderbird/Icedove, it works fine.

Any advice?

 

I've used this setup way back last year, using offlineimap to retrieve messages from my spunge.org mail and serving them up locally via dovecot. Its a bit Rube Goldberg-ish as it basically makes use of IMAP as POP++ then IMAP again, so when I got to the point where I had 500/1000+ messages coming to me per day, I had to quit it. Nowadays I'm coming back to Gnus and using nnimap to connect directly to my IMAP servers instead (I wish No Gnus imports Wanderlust's IMAP library as an alternative nnimap backend soon, though…)

 
Name (required)
E-mail (required - never shown publicly)
Website / Blog address:
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line=""> in your comment.

Subscribe without commenting

`

On This Day...