19

Jan

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 GmailThis 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.

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.app2.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:

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.

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.

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).

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.

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.

[…] 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 […]

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.

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!

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!

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

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:

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.

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.

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.

“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

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!

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.

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.