Configuring IMAP for Gmail, Apple Mail.app, and iPhone (and iPod touch) (and probably iPad)

By Noah | Add a comment | 

Update 5, December 2011: This appears to work for Apple Mail 5 under Lion / OSX 10.7 as well.

Update 4: Step 1.1 is no longer necessary, due to updates in gmail.

Update 3: Sounds like iOS4 addresses some of this with an archive/delete toggle for gmail, as pointed out in the comments.

Update 2: I suspect these instructions will work on an iPad as well as iPhones and iPod touches, but they haven’t been verified. If anyone with an iPad can verify, please post. Thanks!

Update: This post is all about how to get messages to actually delete from gmail when you delete them in Maill.app or on your iPhone, rather than having deleted messages saved in the archive, As Google Intended. If you like the idea of saving every message forever in the gmail archives, their setup instructions are 100% correct and you don’t need this post.


This post was spawned by my frustrations with gmail, and my inclinations to save other people the effort of having to figure it out on their own.

Introduction: IMAP, Gmail, and You
IMAP is a mail protocol that allows continuous synchronization between a mail host and one or many clients; this is a Very Good Thing. For more on IMAP and why you should want to use it, see Google’s introduction, and the first part of this post at TechnoLawyer.

Gmail approaches mail differently than most mail hosts/providers. Rather than filing messages into single folders, messages can be tagged with any number of tags. The advantage of tags over folders is that a single message can be filed in multiple places, each one associated with a different tag. The Inbox is treated as another tag by Gmail. An unfortunate side-effect of this is that when most IMAP clients (mail applications) attempt to delete a message, Gmail removes the Inbox tag, but does not delete the message. The message remains in the archive for that account, and can been seen in the All Mail view. The only exceptions to this behavior are messages in Gmail’s Trash or Spam views; these messages do not appear anywhere else. When they are deleted from Trash or Spam they are gone forever. (Here’s a conceptually useful table of Gmail’s default interactions with IMAP client actions)

It is possible to configure Gmail and Apple’s Mail application to appropriately delete messages from Gmail when they are deleted in Mail. These instructions also show how to store all drafts and saved messages on the Gmail server, and how to configure your iPhone for the same behaviors.

Part One: Configuring Gmail
This step is no longer necessary in the latest version of Gmail.1.1 Go to Settings > Labs and enable Advanced IMAP Controls. Scroll to the bottom and click Save Changes.

1.2 Go to Settings > Forwarding and POP/IMAP. In the IMAP Access section select the following three buttons.

  • Enable IMAP
  • Do not automatically expunge messages
  • Move the message to the Trash

Gmail's IMAP Settings
(For details about these settings, see Google’s blog post.)

1.3 Go to Settings > Labels and select which of the current Gmail labels you want to be visible to your IMAP mail client.

Gmail's Labels

I suggest turning off All Mail. If left visible, the full archive of every (not-yet-deleted) message will be downloaded to your mail client. This can cause a lot of network traffic back and forth between your client and Gmail as the systems keep both versions (local on your computer and remote on the Gmail server) synchronized. This screen doesn’t have a Save button.

Part Two: Configuring Apple’s Mail.app
2.1 If you don’t already have an account set up in Mail, follow Google’s setup instructions for your version of Mail.

2.2 Go to Preferences > Accounts and select your Gmail account and then the Mailbox Behaviors tab. Check all of the following settings:

  • Drafts: Store on server
  • Sent: Store on server, Never delete
  • Junk: Store on server, Never delete
  • Trash: Move deleted messages, and Store deleted messages, Permanently erase after One month

Mail.app v2 Mailbox Behavior Settings

The settings for Sent messages and Trash are the opposite of what Google suggests. It will all work out in the end. When prompted, save your settings.

2.3 Go to Preferences > Junk Mail and uncheck Enable junk mail filtering. Gmail will filter all of the messages for that account. If you have non-Gmail accounts that need filtering, I suggest turning it back on later in step 2.5.

2.4 Tell Mail to use Gmail’s folders for Sent, Drafts, Trash, and Junk mail. 5thirtyone has very clear instructions for this.

1. Highlight ‘[Gmail] Sent Mail’ in the sidebar and select ‘Mailbox’ (menu bar) > ‘Use This Mailbox For’ > ‘Sent’.
2. Highlight ‘[Gmail] Drafts’ in the sidebar and select ‘Mailbox’ (menu bar) > ‘Use This Mailbox For’ > ‘Drafts’
3. Highlight ‘[Gmail] Trash’ in the sidebar and select ‘Mailbox’ (menu bar) > ‘Use This Mailbox For’ > ‘Trash’
4. Highlight ‘[Gmail] Spam’ in the sidebar and select ‘Mailbox’ (menu bar) > ‘Use This Mailbox For’ > ‘Junk’

It may take quite a while to sync these folders between your Mac and the Gmail servers, depending on the number of messages there are to move, and the speed of your connection.

If you turned off junk filtering in step 2.3, you’ll notice that step 4 above doesn’t seem to do anything. It will work if/when you turn junk filtering back on, below.

2.5 If you need junk filtering enabled for your other, non-Gmail accounts in Mail, first get your Gmail account stable, and all of your messages downloaded/synchronized with the above settings.
Once that’s done go to Preferences > Junk Mail and check Enable junk mail filtering.
If you completed step 2.4.4, your Gmail junk mailbox should appear under the Junk hierarchy in the left column of Mail. I haven’t experimented with the junk mail settings much yet. Please comment with success, failure, or erratic behavior. Junk behavior seems to be as expected. Feel free to comment anyway.

That’s it for Mail.app.

Part Three: Configuring mail on the iPhone
If you setup your Gmail account on a recent (OS 1.1.3 or newer) iPhone using the built-in Gmail configurator, you’ll be in good shape. This configuration will actually move messages to the trash when you delete them on the phone.

Google warns that this configuration just isn’t right! and suggests you should manually configure your iPhone to merely archive messages. If that’s what we wanted we wouldn’t be here. So use the iPhone’s default Gmail configurator and get that working. The only other trick is to tell the iPhone to use Gmail server’s folders for Sent, Drafts, and Trash. As above, 5thirtyone has very clear instructions for this.

1. Open ‘Settings’ > ‘Mail’ > [Your Gmail IMAP account] > ‘Advanced’
2. Select ‘Drafts Mailbox’ > ‘On the Server’ > ‘[Gmail] Drafts’. Return to the ‘Advanced’ view.
3. Select ‘Sent Mailbox’ > ‘On the Server’ > ‘[Gmail] Sent Mail’. Return to the ‘Advanced’ view.
4. Select ‘Deleted Mailbox’ > ‘On the Server’ > ‘[Gmail] Trash’. Return to the ‘Advanced’ view.

That’s it for the iPhone.

Check your work
I suggest playing with your systems a little bit to ensure they’re working the way you expect them to. Send yourself a few test messages, file some, delete some, file and then delete some. Do this using Mail and the Gmail web interface. Between steps, compare the status of Mail and Gmail on the web to make sure the behaviors are correct (or at least expected).

Intro to IMAP at Google: http://mail.google.com/support/bin/answer.py?answer=75725
Why IMAP at TechnoLawyer: http://blog.technolawyer.com/2007/10/how-to-convert-.html
Gmail’s default IMAP interactions: http://mail.google.com/support/bin/answer.py?answer=77657
Google’s blog post on advanced IMAP controls: http://gmailblog.blogspot.com/2008/10/new-in-labs-advanced-imap-controls.html
IMAP client setup at Google: http://mail.google.com/support/bin/answer.py?answer=75726
Gmail’s recommended client settings: http://mail.google.com/support/bin/answer.py?answer=78892
Local and remote mailbox mapping from 5thirtyone http://5thirtyone.com/archives/862
Google thoughts on iPhone configuration: http://mail.google.com/support/bin/answer.py?answer=86614

If you found this so useful that you NEED to express your thanks, please click the donate button. Thanks!

Filed in UX  |  Tags: , , , , , ,
digg |  del.icio.us | 


  1. hm, messages wich are recieved(not opened) in Apple Mail are automaticly marked as read? If i keep Apple Mail open it wont give notification on new mail?

    Comment by dek — November 30, 2009 @ 1:10 am

  2. Noah – Great setup. Thanks! How does this change if you’re using multiple gmail accounts? I gather you can’t do the “Use this mailbox for” then?

    Comment by yk — December 10, 2009 @ 12:14 pm

  3. @ YK It should work fine for multiple gmail accounts. Please test and report back!

    Comment by Noah — December 10, 2009 @ 12:23 pm

  4. @ Noah – Fantastic! I left the drafts and spam folders alone. The sent and trash work just as expected. Thank you!

    Comment by yk — December 10, 2009 @ 12:34 pm

  5. Just curious if this set up works in the following situation:

    I have some mail auto-labled on the gmail side. I only want mail truly deleted from gmail if the last label is removed, whether that lable be or etc… I have this working fine now but without having apple mail.app move the deleted messages to the trash folder. The only problem with that is then I have to remember to expunge (cmd-k) in mail.app, or when I use the gmail web interface, tons of messages show up in my inbox.

    I’ll test this out, but was just curious if anyone else already uses a similar set up and has it working.

    Comment by Sean — December 16, 2009 @ 8:32 am

  6. Thanks for this Noah. Having played more, – I have my google apps account set up like this, however I have a second account name.archive@domain.com on my google apps server. I set my account to fwd all incoming email to it and then I also bcc myself with this account from both mail app and iphone.

    This gives you the best of both worlds, an archive somewhere and a simple clean IMAP experience for day to day.

    Comment by George — January 9, 2010 @ 7:28 pm

  7. There is also Mailplane.app which is very slick. Anyone tried it?

    Comment by George — January 9, 2010 @ 7:48 pm

  8. I cannot get my Gmail Mailbox behaviors preferences to save. I change them then they go right back to what they were…. Does anyone have any idea how to fix this?

    Comment by Thom — February 5, 2010 @ 11:09 am

  9. […] gearchiveerde e-mail. Om het netjes aan te praat te krijgen zijn nog wel wat truckjes nodig. Kijk hier en hier als je dit ook zou willen doen. Ik heb het aan de praat en het lijkt prima te werken. Ik […]

    Pingback by De virtuele thuishaven van Leon Pillich » Blog Archive » Happy iMac user — March 6, 2010 @ 9:13 am

  10. […] sessions and you can also sign yourself out remotely. The feature is currently being rolled outConfiguring IMAP for Gmail, Mail.app, and iPhone (and iPod …2.1 If you don't already have an account set up in Mail, follow Google's setup … non-Gmail […]

    Pingback by open gmail account — April 3, 2010 @ 3:56 pm

  11. Hi–I think this is working great–but I had deleted messages off gmail that I had on my computer and still want. I am thoroughly confused about how to reconcile this….


    Comment by Karen — June 3, 2010 @ 5:36 am

  12. @ Hi Karen,

    I’m not sure I understand your question.

    If the messages are already gone from gmail and are not saved anywhere else, they may be gone. Existing messages that have been saved elsewhere and are no longer in gmail shouldn’t cause any problems and should remain where they are, regardless of settings.

    In the future, you can save messages locally by clicking the [+] button in the lower left corner of the left column and selecting New Mailbox… When prompted for location select On My Mac. Once that folder exists, drag messages from gmail into that folder. They will be stored locally, on your Mac, and will no longer be dependent on or synchronized with the gmail account.

    Comment by Noah — June 4, 2010 @ 1:13 am

  13. I’m also having the same problem as Simon.

    I followed your instructions and did: “Spam” > Use this mailbox for > “Junk”. Once I reboot Mail.app tho, it reverts back to how it was before. There is no “Junk” folder, and the “Spam” folder is back under “[Gmail]”. If I try to repeat the process of “use this mailbox for”, it won’t work.

    OS: Snow Leopard 10.6.3
    Mail: 4.2
    Gmail: IMAP

    Hopefully, it is a change by either Apple or Google, or there is a fix. Thanks!

    Comment by Neel — June 17, 2010 @ 6:40 am

  14. Very happy to see that new iPhone iOS 4.0 has feature to turn on or to turn off gmail archiving (turning this off will DELETE files when you delete them). Go to Settings|[Your Gmail IMAP Account] and on the main page there is a setting called “Archive Messages” which can be turned on or off. Setting this to “On” (default) will archive messages when you swipe. Setting to “Off” will delete them. Thanks GMail – finally!

    Comment by Brandt — July 8, 2010 @ 9:24 am

  15. Is anyone else having issues with using Gmail’s Spam folder as the Junk Mailbox? i followed the steps above, to properly sort drafts and trash and such, but the Gmail spam folder won’t budge. I have tried to “use this mailbox for>junk” 50 times and the folder stays put under the Gmail heading. Any suggestions? Thanks!!

    Comment by Kate — July 10, 2010 @ 9:03 pm

  16. Does this configuration still apply if Gmail on iPhone is set up to use ActiveSync? Thanks!

    Comment by kmuri — August 5, 2010 @ 8:11 pm

  17. Hi Kmuri,

    I suspect activesync is a completely different protocol than IMAP, and therefore has different settings.


    Comment by Noah — August 6, 2010 @ 4:38 pm

  18. To those that were asking about the SPAM folders remaining under your [Gmail] hierarchy:

    You should re-read sections 2.3 and 2.4. I am assuming you have turned off the Mail.app junk mail filter as recommended in step 2.3. When you do this, there is no longer a native “Junk” folder so the SPAM folders remain under the [Gmail] hierarchy no matter how many times you try the “Use this mailbox for…” action.

    In the Mail.app preferences, under the Junk Mail heading, I have my mail set up as follows:

    “Enable junk mail filtering” checked.
    “When junk mail arrives” move it to the junk mailbox.

    The check boxes below these items can be on or off; it probably doesn’t matter since Gmail already does such a good job of filtering Spam.

    After some testing, this seems to work. When a message is stored in the “Spam” folder on my online Gmail account it also turns up right away in the “Junk” folder on the Mail.app.

    Hope this helps.

    Comment by tsanzer — October 20, 2010 @ 12:09 pm

  19. And FYI, the new application “Sparrow” may or may not be for you. I am trying it out right now. It is very bare bones and still in Beta, but it does all of the set up correctly in one click. That is, all of the above is achieved without having to mess around under the hood. So if you still find you are having problems, this is a nice alternative. Actually, my Mail works fine but I am thinking of switching anyways.

    Comment by tsanzer — October 20, 2010 @ 12:15 pm

  20. I have followed all these suggestions. I chose “use this mail box for” all the various folders under Gmail, drafts , spam, sent, trash. Under the top, Mailboxes, Trash now does have a drop menu showing “On My Mac” and “Gmail”. However, there is no drop menu for the other folders of Sent and Junk. All email that I send and receive does show up under the Sent and inbox. I originally had a drop menu under Sent and now it has disappeared. There never appeared a drop menu for Junk or Drafts. How do I get these? Thank for your help.

    Comment by Aneita — December 31, 2010 @ 3:33 am

  21. I’m pretty sure you would only get dropdown menus if you have multiple accounts. Trash shows a dropdown menu because there is a default “On My Mac” trash bin as well (this can be deleted if you choose). There shouldn’t be any other dropdown selections – nor do you need them. If I am not answering your question please explain what effect you are trying to achieve. As it is now, however, it seems like you got it working correctly.

    Comment by tsanzer — January 15, 2011 @ 2:08 pm

  22. Any idea why the “advanced imap controls” lab mention would not be an accessible lab in gmail settings?

    I’m stumped.

    Comment by Will — June 12, 2011 @ 7:29 pm

  23. Looks like this lab actually no longer exists in the gmail settings.

    “Today we’re excited to graduate three more features from the experimental testing ground of Gmail Labs. Superstars, Nested Labels, and Advanced IMAP Controls are now first-class citizens in the Gmail world, thanks largely to your feedback,” Maciek Nowakowski, Associate Product Manager at Google, announced


    Comment by Will — June 12, 2011 @ 7:45 pm

  24. @ Will, thanks for the update.

    Comment by Noah — June 14, 2011 @ 11:46 am

  25. I have followed the instructions but can’t seem to do the following – if I create a draft e-mail on the iphone, it is now synced to ‘drafts’ in gmail – however it isn’t a ‘normal’ draft in that you can’t seem to amend it, only copy it into a new e-mail. Do you have any suggestions? Thank you!

    Comment by Joanne — July 15, 2011 @ 4:48 am

  26. I still use this setup since I discovered it a couple of years ago. Thank you!

    Comment by Tim — July 26, 2011 @ 4:50 pm

  27. Hello,
    I followed the instructions and am able to send e-mails but not receive. I have an error saying “The connection to the server “imap.gmail.com” on port 993 timed out. I have Suddenlink Cable as my ISP and am using a Motorolla sbg900 modem with an apple Airport Extreme Router. I have researched this problem as it appears to be a pretty prevalent problem but have yet to find an answer. Thanks for your time.

    Comment by Kevin — December 29, 2011 @ 9:56 am

  28. Update – I still had the firewall on the Motorolla SBG900. Confirmed the firewall on the AE was on and allowing all incoming connections via Mail then turned the firewall off on the SBG900. Presto, gmail started synching to the Apple Mail. The rest of the directions should work now. Updated for anyone else having the same issue.

    Comment by Kevin — December 29, 2011 @ 10:43 am

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.