Back to HOWTOs

Backing Up Gmail with Thunderbird Using IMAP


As I become more and more reliant on Gmail, I've looked for an efficient way to back up all my messages in Gmail to my local computer for a couple of reasons:
  1. Gmail Failure: While very unlikely, there's always the occasional story of someone whose Gmail account just gets closed and they've lost all their email. Once the messages are on my local drive, then I can back them up to external hard drives like other files on my disk. So, I'm covered if Gmail fails or my local hard drive fails.
  2. Offline Access: Especially, if you travel a lot, it can be nice to have all your messages accessible when you have no Internet connection. Google has started an offline option in the Labs. However, there offline technique doesn't download everything, but guesses at which messages you're mostly likely to need (e.g., recent ones). This is probably sufficient most of the time, but inevitably there might be a time when that one message you really want wasn't downloaded offline. By having all your messages and attachments offline, you never have to worry about missing a message.

There is a Gmail Backup program, however it is not open source and you have to trust it with your Gmail password. Another method mentioned in some HOWTOs is to download all your messages via POP3. However, this doesn't synchronize your local actions (e.g., deleting and moving messages) with Gmail. My overall goal is to have a mirror of my Gmail account on my desktop and any action I do locally or in Gmail is automatically synchronized.

So, this HOWTO does the backup using Thunderbird (best offline email client of which I know) and IMAP. Thunderbird has most all the IMAP options to keep your entire Gmail account synchonized, but several key settings are hidden away in config values that have to be changed.


  • Follow these instructions to configure Thunderbird for Gmail IMAP. Use these recommended settings.
  • Familiarize yourself with how Thunderbird actions will synchonize with Gmail. One thing in particular to note:
    • IMAP translates labels with a forward slash (/) into a folder hierarchy like you see in your computer's file system. If you have a label such as 'Family/Friends,' you may want to reconsider your naming schemes because your IMAP client will display it as a folder named 'Family' with a subfolder named 'Friends.'
  • In Thunderbird, right click on new account in "All Folders" pane and "Subscribe..." and subscribe to all the Gmail folders of interest.
  • In "Tools->Account Settings->Offline & Disk Space" check "Make the messages in my Inbox available when I am working offline" and "When I create new folders, select them for offline use". Click the "Select folders for offline use..." button and select all the folders you want available for offline use.
  • Now there are some config settings you have to edit. Toggle mail.server.default.mime_parts_on_demand to false so that attachments are downloaded offline.
  • Toggle mail.check_all_imap_folders_for_new to true so that all remote folders are checked for new mail automatically instead of needing to click on them in order for new messages to be checked for.
  • Set mail.imap.use_status_for_biff to false to explicitly select each folder to update its messages rather than using the STATUS command.
  • Set mail.server.default.autosync_offline_stores to true to force Thunderbird to download messages for offline use whenever you open a folder or it detects new mail (so downloading is not delayed until you go offline). These do not exist in the config editor even though Thunderbird has build in support, so they need created.
  • Now, you should be setup to have all your Gmail messages sync'd with Thunderbird. The remainder of the items are optional to help make the Thunderbird-Gmail intergration more efficient. Check the checkmark for "Tools->Options-> Advanced->Show expanded columns in the folder pane" and then click on "Unread" and/or "Total" in the small column control at the upper right corner of the folder pane. This will display how many messages are in each folder.
  • Click on the tiny "display message threads" button to see replies in a hierarchical order in Thunderbird (kind of like Gmail's conversation view, but not quite the same). Also, if you use threaded views, you may was to set mailnews.thread_pane_column_unthreads to false to allow you to sort by other fields while still keeping the view threaded (otherwise, sorting by, say, received date will break you out of threaded view). Note: In Thunderbird 3, the Extra Folder Columns extension needs to be installed to do this.
  • Install the Display Quota extension to see your Gmail quota usage in Thunderbird.
  • To synchronized your Gmail and Thunderbird contacts, install the Zindus extension.
  • To create some useful keyboard shortcuts, install the Nostalgy extension. In particular, I map the keyboard shortcuts "#" and "!" to send a message to Gmail's Trash and Spam, respectively (just like the Gmail shortcuts).
  • I also installed the Buttons! extension so I could use the Archive! button to move messages to Gmail's trash with one button click (if I don't want to use the keyboard shortcut).
  • Note that the new mail notification system doesn't seem to work very well since it may notifiy you when there is new mail in "Sent Mail" or "All Mail", which probably isn't what you want. You can refer to this technique to disable the Thunderbird system tray notification. An extension like Mailbox Alert may help with more fine-grained control over new mail notifications (e.g,. per folder).
  • You also may want to refer to this page for some more details about how Thunderbird and Gmail integrate.