Using Gmail with Apple Mail

I recently moved my e-mail services from a Courier-based Maildir system to Google Apps / Gmail. Times are tough and I just couldn’t make a case for paying for hosted e-mail anymore. Gmail for Google Apps is free, each user gets 7+ gigs of storage and each user can manage their own account (password changes et al).

I’ve been trying to get Gmail and Apple Mail to play nice with each other when loading mail via IMAP. The first problem to solve was how to remove the [Gmail], All Mail and Starred from showing in the folders list. The second problem was reconciling the different Sent/Trash/Draft folders that each system uses. And finally there was an issue of some emails that got out of sync between client and server.

What is IMAP? The Internet Message Access Protocol lets you read your email on a server (like Gmail) on your computer in an email reader (like Apple Mail) without having to use a slower web interface. It is the hipper version of POP3, supporting server-side folders, searching and “push” mail notification.

FWIW, I did this using OS X Snow Leopard (v 10.6.7) and Mail 4.5, with a total of 41, 388 inbox messages and 14, 545 outbox messages.

Removing “All Mail” from the folder list

Gmail’s All Mail (and Starred) are virtual mailboxes that show a special view of your mail within the Gmail interface. But outside of the Gmail  interface, they appear as real mailboxes, not virtual ones. So when creating a Smart Mailbox, emails are counted twice: once from the Inbox and once again from All Mail. In searching for a solution, I found people trying to build Smart Mailbox rules to work around this, but that is the wrong approach. The right approach is to just get rid of the damn thing. Here are the steps:

  1. Login to Gmail and go to the Settings page.
  2. One of the Settings tabs to the right is Labs – select it.
  3. Look for a Lab called Advanced IMAP Controls and enable it. Then click the button marked Save Changes.
  4. Now, go back to the Settings page and select the tab called Labels.
  5. Find the “All Mail” system label and deselect Show in IMAP. While you’re at it, do the same for “Starred”.

Reconciling the Sent, Draft, Junk and Trash folders.

Apple Mail and Gmail use different IMAP folder names for each of the special folders. That’s because IMAP does not specify a standard set of names for the special folders. So for example, Gmail puts sent messages into a folder called “Sent” and Mail puts them into one called “Sent Messages” so that there are two places for sent mail. Ridiculous! Let’s fix it:

  1. In Apple Mail, make sure you can see your Mailboxes sidebar on the left. If you can’t, go the Mail -> View menu and select Show Mailboxes.
  2. Find our Gmail account on the left hand side and expand it (click on the small triangle to the left of the name of your Gmail account), then expand the [Gmail] mailbox under that.
  3. For each of the four special folders listed under [Gmail] go the Mail -> Mailbox -> Use This Mailbox For menu and choose the special folder it should be assigned to. For example, select the “Spam” folder listed under [Gmail] and select Use This Mailbox For -> Junk. If you have multiple accounts don’t worry, Apple Mail will handle all that internally.
  4. When the original Apple Mail special folders are “released” from their duty, they will magically appear as IMAP folders in the Gmail account. Feel free to move their contents to the appropriate Sent/Trash/Draft/Junk under MAILBOXES and then delete them.
  5. Finally, in Mail -> Preferences -> Accounts -> Mailbox Behaviors, for Drafts, Sent, Junk and Trash choose to store messages on the server. For Trash, also choose to move deleted messages to the Trash mailbox.

Removing [Gmail] from the folder list

If you’ve followed along so far, the only thing showing in the folder list is [Gmail], along with any custom folders you may have created on the server. But since the [Gmail] folder is now empty, it serves no purpose and is unsightly. How to get rid of it? We have to change the server namespace (a fancy word for filepath) Apple uses by default to the one Gmail’s prefers.

But there’s a catch of course. Apple Mail uses the root as the default. Your inbox lives in root. And so do any folders you may have created on the server. Upon changing the namespace, Mail will no longer be able to see these folders. So here’s what we do:

  1. In the folder list, drag and drop all folders you’ve created on the IMAP server into the [Gmail] subfolder.
  2. In the Mail -> Preferences -> Accounts -> Advanced menu, enter [Gmail] for IMAP Path Prefix. After a brief delay, [Gmail] will disappear and all your folders will now appear to be back “in the root”
  3. But the inbox will now be empty. Login in to Gmail, move all the emails from the inbox to a temporary mailbox. Then move them all back to inbox. Synchronize the account in Apple Mail to show the changes.

Synchronizing Emails between Gmail and Apple Mail

Once I was done my transition, some emails were showing the incorrect date and incorrect content. This one is easy to fix. Choose the mailbox in Apple Mail that is misbehaving and from the Mail -> Mailbox menu select Rebuild.

This entry was posted in OS X, Programmer. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>