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
(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.
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
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!