Setup Gmail IMAP, Mail.app, and the iPhone with Archive

Jon Shea November 17th, 2008

If you’re happy using gmail.com as your user interface, then there’s no need to read further into this blog post. The Gmail web interface is the best I’ve ever used, but it’s not as good as a native, desktop app. If you wail on your applications like I do, then you need fast and local. Apple’s Mail.app isn’t prefect (no email client is), but it’s good enough. The interface is snappy, the search is fast and reliable, and I can drag and drop attachment files onto it.

I’m going to explain how to setup Gmail to work the right way with Mail.app and the iPhone. “Right”, of course, means “the way I want it to work.” In particular, this means that I want “deleting” something in my client to make it “archived” in Gmail for eternity. I almost never want an email to be deleted forever. I also want Sent Messages and Drafts to work in a reasonable way, but delete -> archive is the big one for me.

NB: This guide is a work in progress, a living document. Check back for updates. Feedback is actively solicited.

Setting up Mail.app

  1. Follow the directions at the Gmail Help Center. Make sure you enable IMAP in the Gmail web interface before you play with Mail.app. Also, when Mail.app notices you’re setting up a Gmail account and offers to do it for you automatically, don’t fall for it. It will setup and POP3 account, which is worthless, and you’ll have to start over. Finally, note that every time you’re ever asked for a “User Name:” you’re going to have to enter your whole Gmail address username@gmail.com.

  2. As always, the devil is in the details. In this case, the details are the “Mailbox Behaviors” panel for the account in Mail.app preferences. Google has Recommended IMAP client settings, an obscure Gmail Help Center page, and the Mail.app settings are unlinkably hidden by Javascript. I believe Google’s recommended settings are wrong. Well, I think their “Sent” recommendation is wrong, I agree with the other ones. Here is my recommendation.

mailapp_settings.png

If you match these settings then your Drafts, Sent, and Junk folders will automatically sync with the corresponding Gmail folders. Your local Trash folder will remain empty, and your deleted messages will get archived in Gmail’s “All Mail” folder.

If “Sent” is not checked, then Gmail stores a copy in its Sent Mail folder, and Mail.app will store a copy in its Sent folder. These two copies will be different, and deleting one will not delete the other. The ”Delete sent messages when:” setting will only apply to the Mail.app copy. If that’s what you’re into, then go for it.

A few caveats

Gmail Folders in Mail.app

Gmail Folders in Mail.app

After following the above directions, Mail.app may or may not have figured out how to merge the the Gmail tags with the corresponding Mail.app folder. For example, the Gmail “Spam” tag and the Mail.app “Trash” folder. In the worst case, if Mail.app figures out nothing, then your Gmail setup in Mail.app’s main window will look like the image to the left. If this is the case, then click on a folder that Mail.app did not figure out for you. Let’s start with “Drafts”. Click on the “Mailbox” menu, pull down to “Use This Mailbox For”, and select “Drafts”. Repeat as necessary for “Sent Mail”, and “Spam”. Do not do this for “Trash”. If you do, then Mail.app will silently turn on “Move deleted messages to the Trash mailbox”__ and your archived mail will start getting silently deleted. Oofta. Also, for some reason my copy of Mail usually won’t merge “Spam” with it’s “Junk” folder. I’ve given up on trying to make it work, because it doesn’t really matter anyway.

You may have noticed that with the above settings you lose the Trash folder in Mail.app. That is, you will have no record of your recently deleted messages except for Gmail’s “All Mail” folder (Mail.app’s Trash will be forever empty). I’m fine with that, since deleted messages are the overwhelming majority of my “All Mail” folder. Another option is to make a costume tag in Gmail like “[Deleted Messages]”, and then set this to be the Trash folder in Mail.app. Then, when you delete the message Mail.app will remove all existing tags, and add a [Deleted Messages] tag. If you delete it againOther option. Make a [Deleted Messages] folder yourself.

Setting the “IMAP Prefix”

In the Mail.app sidebar your Gmail tags will appear as folders. The built in Gmail tags (All Mail, Spam, Starred, Trash) appear nested in a folder named [Gmail]. The rest of your tags appear as folders at the same level as the [Gmail] folder. Some people recommend that you set your IMAP path prefix (in Preferences -> Accounts -> Advanced -> IMAP path prefix:) to Gmail. I don not recommend this. It will make your built in Gmail tags appear at the top level, but it will make your personal tags disappear entirely. Also, if you fiddle with it Mail.app will re-download your entire mailbox. Fair warning.

Setting up iPhone Mail

First, and important FYI: there are two different and barely distinguishable types of Gmail accounts on the iPhone. If you go to “Mail, Contacts, Calendar” settings, then “Add account…”, and select “Gmail” then you will get an account type that I will call “POP3”, even though I’n not certain it is POP3. This potentially out of date video calls it POP3, though the obscure page calls it IMAP. Regardless of what it is, you can’t make it work the way we want.

Amazingly, if you let iTunes sync your Mail.app Gmail IMAP account to the iPhone, the iPhone will turn it into a maybe-POP3 account. Furthermore, if you have a mail account on the iPhone that looks like an account in Mail.app, but isn’t quite the same, then iTunes will be unhappy about syncing. So the first order of business is to stop iTunes from trying to sync your Mail.app Gmail account to your iPhone. Plug in your iPhone, find it in iTunes, click on the Info tab, scroll down to Mail Accounts, and uncheck your gmail account. Then, since you can’t plug in an iPod without it syncing, go delete the account from your iPhone.

Bad Gmail probably-POP3 Account

Gmail non-IMAP “Auto-G” Type Account

The only way to get a Gmail IMAP account on the iPhone is to instead select “Other” at the account creation screen, and fill out the settings by hand. Instructions are on this page, or you can follow the above previously linked video. Note once again that you need to type out the full username@gmail.com each time.

After you’ve added your account information, quit the Settings app, then fire up Mail and let it download at least your folder structure. If you don’t do this, then the iPhone will let you fiddle with settings using only a fake INBOX folder that it assumes your account will have. Then, after it downloads your real folders, it will silently throw out the settings you put on the fake INBOX folder and replace them with its own defaults. I kid you not.

iPhone Gmail “IMAP” account

iPhone Gmail “IMAP” account

Once again, Google recommends that you keep a separate copy your sent messages on the iPhone on its Recommended IMAP client settings page, and I disagree. My settings are in the image below.

My recommended Gmail settings

My recommended Gmail settings

Also, while Mail.app will let you live your life without any Trash folder at all, the iPhone isn’t so understanding. It demands somewhere that it can put a Deleted Mailbox. Put it “On My iPhone” and it will make a separate Trash completely independent from Gmail. You can delete these message on your iPhone whenever you want, and it will not effect Gmail at all.


Other notes

This is a lightly tested theory: if you enter username instead of username@gmail.com then you will download new messages ok, but your deletes and folder moves will not propagate to the server correctly. Oofta.

Heinous iPhone Bug: If you make a new account with the same settings as an existing account, then the client will merge the two accounts with the new one’s blank settings, and erase the data in the old one. If you delete one, then it will delete both.

Advanced IMAP Settings

Google Labs recently released Advanced IMAP Controls for Gmail. If you activate advanced IMAP controls then you can choose to make some folders “invisible” to the IMAP interface. Some people are really excited about this, because they don’t want to download their huge “All Mail” folder. Mail.app will only download it once anyway (and then you have an offline copy), and the iPhone only downloadss 50 at a time, so I don’t see what the big deal is.

The advanced controls also expose a completely incomprehensible feature to let you “turn off auto-expunge”. When this came out about 100 people reblogged it, and it’s pretty clear that no one knows what it does or how it’s supposed to work. According to the official Google post:

The IMAP protocol allows messages to be marked for deletion, a sort of limbo state where a message is still present in the folder but slated to be deleted the next time the folder is expunged. In our standard IMAP implementation, when you mark a message as deleted, Gmail doesn’t let it linger in that state — it deletes (or auto-expunges) it from the folder right away. If you want the two-stage delete process, after you’ve enabled this Lab, just select ‘Do not automatically expunge messages’ under the ‘Forwarding and POP/IMAP’ tab in Settings.

Um, ok. First off, what is “expunge” supposed to mean, and what does it mean to Google? Second, if deleted messages aren’t immediately expunged, then when are they expunged? Once a month? When you click the “expunge” button? (There is no expunge button). Third, that option to “Do not automatically expunge messages” followed by “When a message is expunged from the last visible IMAP folder: Archive the message” is pretty tempting. It’s a trap! As far as I can tell, with every other permutation of settings this will make deleted messages go to the Trash and then disappear forever.

I held out a long time before making the move to Gmail. I got an invite soon enough to get my second favorite username, but then I sat on it for years without using it. At first it was because I was too hardcore to let the gRobot read my email. Later, when I’d become less of an idealist and more of a pragmatist, it was because Gmail didn’t support IMAP. When IMAP support was added last year, I didn’t move because I was to lazy to migrate. Eventually my other mail server went down at an inopportune time, and I decided to make the leap.

Pages with potentially useful information

Deleting IMAP Messages

Apple iPhone and Gmail deleted messages

IMAP Actions

Gmail Archiving and deleting on iPhones

Advanced IMAP Controls

Advice that doesn’t quite work

Other iPhone tips we’ve written about

Double tap for iPod Controls

Mac Retrogaming on your iPhone with minivMac.app

Turn Your iPhone 3g into a Wireless Hard Drive

iPhone: Charge while your Mac sleeps

Tags:

30 Responses to “Setup Gmail IMAP, Mail.app, and the iPhone with Archive”

  1. Tom Says:

    How do you deal with the IMAP Path Prefix? Do you set it to ‘[Gmail]‘ or not? It’s the one in Advanced Settings of Mail.app

  2. Jon Shea Says:

    Hey Tom. I do not set IMAP Path Prefix to [Gmail]. My experience, and correct me if yours is different, is that setting this will make the Gmail tags (All Mail, Spam, Starred, Trash) appear at the “top level” in Mail.app sidebar (rather than nested in the “[Gmail]” folder. However, it also makes your other tags disappear entirely from Mail.app.

  3. Eric Fields Says:

    So we don’t assign Gmail’s Trash folder anywhere. When I delete something from Mail.app, where does it go?

    Have you experimented with setting your Gmail account’s Trash mailbox in Mail.app to All Mail?

  4. Eric Fields Says:

    For the record, this was the best guide for setting up Mail.app thus far. Its a pain in the ass with Gmail. I lived in duplicate-drafts land for months and finally nuked all prefs and started over. So far, perfect.

    Thanks so much.

  5. Louis Says:

    Great article! Thanks a lot for the useful information. I’ve always felt that the Google instructions were vague, so I really appreciate this page. One more question for you. On the iPhone settings screen capture that you posted above, the trash is set to be placed on the iPhone and it is set to never be cleared. Since this will result in a ton of emails on your phone, would it be alright to have these messages deleted periodically? I’m wondering if having these messages cleaned out every month or so will remove them from the “all mail” folder. Thanks again.

  6. Jon Shea Says:

    Eric: Remember, technical folders in Mail.app are tags in Gmail. When you delete something in Mail.app it sends a delete message to Gmail, which then simply removes the tag from that message. So when you delete a message in your Inbox in Mail.app, Gmail will remove the “Inbox” tag from that message. Since untagged messages remain in “All Mail” this gets you exactly what you want.

    It’s been a while since I’ve tested this, but I believe that if you set Mail.app’s Trash to “All Mail” then Mail.app will do something like tell Gmail to delete the message from Inbox, and then it will add a copy of the message to “All Mail”. I don’t remember exactly what happened, but I’m pretty sure I tried that, and that it didn’t work the way I wanted it to. Maybe it made two copies in All Mail or something.

    Louis: I don’t use email on my iPhone very much, so I’m too worried about wasting space with it. However, when set up the way I describe (Deleted Message: On My iPhone) you can delete email from the iPhone trash whenever you want, and it will have no effect on Gmail at all.

  7. Louis Says:

    Hi Jon, So I’ve been using gmail set up the way you describe for both Mail.app and the iPhone. Let me just say, things have been working great! I have one question. I’ve noticed that when I’m composing a message using Mail.app, draft messages get saved frequently as I compose them, and then once I send the email all of the copies are placed in the [gmail]/trash folder. So right, for example, I have 3 copies of the same email in my trash folder with different time stamps. Is this something you have encountered? Do you think it would help to either 1) not save drafts on the server, or 2) just wait for the 30 days at which point the Gmail web account automatically deletes trash anyway? Thank again.

  8. Jay Allen Says:

    FWIW, your Markdown is showing on all posts.

  9. Craig Atkinson Says:

    Hi Jon, I’ve tried all this – do you reckon it works with google apps mail for domains too? Thanks Craig

  10. Jon Shea Says:

    Craig, I haven’t tested it with Google Apps, but I don’t see why it would be different. My understanding is that Google Apps just got support for Gmails beta / labs features too (not that I recommend any of them for Mail / iPhone IMAP). If you report back, I’d love to update the post with your experience.

  11. Craig Atkinson Says:

    Right, it seems to work fine. Things I’ve found so far: The ‘All Mail’ folder doesn’t update too fast having read mail in ‘Inbox’. It does eventually though and doesn’t bother me greatly! Mail app also seems to be displaying images now too, it didn’t last time I tried a few weeks ago – Leopard, MBP 15.4″. I got the junk / spam folder thing to work, however it has reverted and I just have the gmail spam folder now. I was wondering, when you delete it’s contents using mail app do they get archived or deleted? Think that’s it. Seems very usable! Thanks Craig

  12. Craig Atkinson Says:

    Actually turns out there does seem to be a problem, I just realised. When I reply to received mail it gets stored in the trash in mail app, and the tras in gmail. Not great, obviously! Any help with this would be great, I don’t want to fiddle with stuff too much due to fear of losing my mail!

  13. Craig Atkinson Says:

    To add to my last post, when replying to a google apps mail using mail app IMAP: Mail app stores a draft every couple of words, it gets stored in the gmail-trash folder and the trash in gmail itself. It seems it’s not the message getting trashed, just a million drafts of it. Quite annoying!

  14. Jon Shea Says:

    Craig: I have the same thing going on. I bet you can make it go away if you choose not to save your drafts on the server. The side effect, of course, is that you’re drafts won’t be on the server or propagate between different IMAP clients.

    I don’t really mind the drafts that litter the Trash, because I don’t use the Trash for anything. I only even look at the Trash by mistake. All of the mail I want (all the mail I get, for that matter) ends up in All Mail.

  15. rick Says:

    have you tried this with multiple gmail accounts in mail app? wouldn’t the “merge the the Gmail tags with the corresponding Mail.app folder” run into issues?

  16. shaan Says:

    thanks so much for this article, have been migrating my domain to google apps, i currently use Mailplane, which is ok, but is really just a gmail shell, this guide is perfect.

  17. Alex Says:

    This was a very useful article, but …

    How do you really delete things when you want to? I’m more comfortable with the usual IMAP behavior in Mail.app, where one uses the delete button to get rid of things one really does not want to see ever again. I get a lot of such emails, and see no reason to clutter my “all mail” folder with them—they show up during searches etc.

    So, to archive a message I drag it into a “Saved Mail” mailbox; I could sort into multiple mailboxes as I do for work (many tens of them, by year and then by subject within years) if I wanted, but have not yet set that up. My settings are: checked – store draft … unchecked – store notes … (I do not use notes) checked – store sent … / delete never checked – store junk … / delete when 1 month old checked – move deleted messages to the Trash mailbox checked – store deleted messages on the server permanently erase deleted messages: never (I do this by hand)

  18. Alex Says:

    Trying again — my line breaks were deleted in the posting …

    This was a very useful article, but …

    How do you really delete things when you want to? I’m more comfortable with the usual IMAP behavior in Mail.app, where one uses the delete button to get rid of things one really does not want to see ever again. I get a lot of such emails, and see no reason to clutter my “all mail” folder with them—they show up during searches etc.

    So, to archive a message I drag it into a “Saved Mail” mailbox; I could sort into multiple mailboxes as I do for work (many tens of them, by year and then by subject within years) if I wanted, but have not yet set that up. My settings are:

    checked – store draft …

    unchecked – store notes … (I do not use notes)

    checked – store sent … / delete never

    checked – store junk … / delete when 1 month old

    checked – move deleted messages to the Trash mailbox

    checked – store deleted messages on the server

    permanently erase deleted messages: never (I do this by hand)

  19. Sean Greathead Says:

    I have one challenge which I cannot seem to get resolution on regarding Gmail IMAP and Mail.app. If I move mail on Gmail giving it a label, it does not move on my Mail.app. Yet, the reverse happens. Any thoughts?

  20. Eric D. Fields Says:

    I’m back!

    I followed your advice for the iPhone after having some weirdness between syncing. That was enlightening.

    In the age of IMAP, having iTunes sync your mail accounts instead of just relying on the iPhone to do its own thing with IMAP is a little silly. I can’t imagine there’s too many iPhone users who are still on POP mail accounts anyway. But I guess Apple’s goal is simplicity, and checking a checkbox is far more easy.

    Back to Mail.app… when the Inbox has focus, the title bar of Mail.app says that I have “(4294967170 messages)” … even with my huge gmail archive, I don’t think its that many… it can’t be. No human can digest that many emails in the 3+ years I’ve been using gmail/Google apps. Any thoughts?

  21. Nick L Says:

    Hey this really is a great tutorial. I did everything almost exactly the same on mine except for the archiving.

    I am like Alex and when I delete something I know I never want to see it again. So I route the trash folder in Mail to Gmail’s Trash folder and checked the “store delete messages on the server” and then people can choose to either delete them manually when they want or have them permanently erased after a certain amount of time. I also differ from Alex in that I don’t have junk delete itself after a month because I would like to monitor that and make sure nothing goes into junk on accident and gets deleted. I guess this is just preference.

    My point is, I love this article but to make it better I think you should throw in the option for people that aren’t big on archiving email and mention it in your blog and maybe give some brief instructions (Also how to do the same thing on the iPhone). I can see business people or people that rely on email a lot needing archives, but for a student and other simple emailers, like myself it isn’t a big deal and I just let Time Machine back up what I keep on my computer.

  22. Portable Air Conditioners.net Says:

    I use Gmail on my iphone 3g..and it always worked fine, until all of a sudden it stopped working. It would not update my email and just say “connecting….” and then “cannot connect to imap.google.com”. It was so frustrating! I tried several things, none of which worked. Finally I got a tip from someone online to just go into gmail on my computer and change my password to something more secure. Up until then my password had just been a simple word, but after changing it to something with a number and longer word in it, gmail worked on my phone again. But gosh it was so frustrating when it wasn’t working.

  23. Jan Brejcha Says:

    I’d leave “store sent messages on the server” unchecked, since using smtp.gmail.com already puts all your outgoing mail in the sent folder on the server.

  24. katy lavallee Says:

    I just followed the instructions to set this up, but before I changed the default trash settings I deleted some messages on my phone to see what it would do. By default, it archived the message in “All Mail” and applied the label “Deleted Messages”. This works great for me, because I can dismiss anything I want on my phone with the trash icon, then later if I decide I need to really delete stuff, I can look under “Deleted Messages” through the browser interface and start removing items. And if I know I only want to archive something or want it in the trash, I can file it away with the folder icon.

  25. katy lavallee Says:

    Okay, but it didn’t automagically get set up like that for my work account, which is through Google Apps. Anyway, since I liked that behavior, I created a “Deleted Messages” label through the browser interface, and then set that as my trash on the iPhone. When I exit settings and come back, it has “Deleted Messages” set as a top-level folder with a trash can icon. I don’t know if “Deleted Messages” is a magic phrase, or if it would do that with any label I assigned as trash, but it’s pretty cool.

  26. Anders Moldin Says:

    I followed your instructions for Mail.app but when I delete a message it turns grey and stays in the inbox. When I log in via Gmail, it sits dutifully in my inbox there, as well. What can have gone wrong, or can I have done wrong?

    http://tinypic.com/r/2wcfi4w/5

  27. wrongful death lawyer Says:

    Great work! I also have my own blog I just find it hard to write quality content like this. I guess I really don’t have the time.

  28. links for 2009-10-19 « Amy G. Dala Says:

    [...] ExpanDrivel » Setup Gmail IMAP, Mail.app, and the iPhone with Archive – The ExpanDrive Blog (tags: iphone osx tips email google) [...]

  29. Gus Augeri Says:

    If the VPN access address isn’t blocked by the Chinese government, then that must mean they approve of it. Otherwise, they would block it. Therefore, it’s not illegal.

  30. Apple Says:

    If you are using a DVD from Linux Format (out of the UK) they give instructions in the magazine and probably on the DVD on how to setup a CD from the DVD. Linux Magazine (also out of Europe) may provide the same.

Leave a Reply

Subscribe:

Add to Google
RSS
Try ExpanDrive

If you’ve heard of SSH then you need ExpanDrive.