How to set up Apple Mail for better Gmail IMAP support

05/11/2008 - UPDATE: Google Labs have added advanced IMAP controls which means this hack is no longer required. Find out more in our article, Google adds IMAP controls to Gmail and Google Apps

We have been using Google Apps (www.google.com/a/) for over seven months now. This should apply the same to Gmail as well.

While it's generally been fantastic with few, if any, major problems, there is one frustrating thing about it relating to Google's implementation of the IMAP protocol.

Google has a somewhat odd IMAP folder structure with a [Gmail] folder containing "all mail", Starred, Sent, Drafts etc.

The problem is that you have no choice in Apple Mail to unsubscribe from the [Gmail] (and therefor "all mail") folder. From what I've read, this may actually be an issue with the way Gmail implements IMAP preventing anyone from subscribing/unsubscribing from folders.

The result is that you end up with doubles (or more) of literally every email in your inbox. In my case, I have 12,000+ emails in my email account so this is a lot of extra emails, traffic and disk space.

Some have suggested specifying the [Gmail] prefix in IMAP set up however this means you can't actually see your INBOX but can see "all mail" as well as the other folders shown above. Not nice.

The solution

I have tried this before, I'm sure, but for some reason I don't remember it working. However, I've recently set up half a dozen or so email accounts like this and it seems to be working perfectly.

The trick is simply to specify INBOX as the IMAP Path Prefix in your email program (i.e., Apple Mail).

What this does is set the "root" of your email access to the inbox meaning all the extra folders such as "all mail" are below the root and thus not shown.

If you have any folders that you previously had in your inbox (i.e., INBOX/A Folder), you can still show these inline in your Apple Mail inbox by labelling them INBOX/INBOX/A folder (not so pretty in Gmail but works perfectly in Mail).

Suggestions

if you send your outgoing emails through the Gmail servers (smtp.gmail.com), which I recommend you do, sent messages are automatically stored in your sent messages folder so it is recommended you set Mail to not store sent messages on the server.

This is important and I strongly recommend you uncheck this and save changes to your email settings prior to implementing the INBOX prefix above. If you don't you might find you can't access from Mail any previous sent messages unless you copy them back down which is complicated and time consuming.

Conclusion

This seems to fix a long-standing problem I have had with Google Apps / Gmail and Apple Mail. I am interested to know if this works for others and, if not, what their experience has been. If everything falls apart, don't stress, your emails on the server have not been affected and the worst-case scenario is that you would have to delete your email account in Mail and set it up again.

29 Responses to “How to set up Apple Mail for better Gmail IMAP support”

  1. Jul 26
    11:25 AM
    point.mutation

    worked well for me!

  2. Jul 28
    12:02 AM
    Darren Roberts

    This doesn't seem to working quite right. I can't see any Trash Can in mail when I delete from INBOX and see nothing in Mail Sent either. Could you explain in a bit more detail how you set up the IMAP folder mapping before applying the INBOX prefix.

  3. Aug 02
    09:13 AM

    Darren, I suggest you do not store Sent, Draft, Junk or Deleted messages on the server. Before you change the prefix to INBOX, change these settings and click save. The only problem with this setup is that you can't store drafts on the server but I found Gmail saved about a dozen copies of drafts on the server which is really frustrating anyway.

  4. Aug 06
    09:05 AM
    Bryan

    Great! The only downside that I can notice right now is that email sent on gmail's interface does not sync in Apple mail. That is unless anyone here knows of an answer.

  5. Aug 06
    03:33 PM
    Jose

    I already have my account setup to "Use this mail box As..." Option, wil I have to disable this in order for this to work?

  6. Aug 11
    11:04 AM

    Bryan, you should be sending with Gmail's servers, smtp.gmail.com. In this case, Sent messages are stored automatically on the server and Apple Mail stores them locally, too. They are not synced, though. There are ways around this to do with using filters in Gmail but you'll likely end up with duplicate emails again in Mail. Jose, I suggest you uncheck store sent/drafts/trash/junk on the server BEFORE implementing this change. Sync your account then change the prefix to INBOX.

  7. Aug 19
    03:56 PM
    bulge

    This is a great tip!!!! Also, I have tried keeping my sent items on the server, and low and behold... it seems that there aren't duplicates being made. Even though I send via smtp.gmail.com, it seems to just tag the one in the Gmail "Sent" with the label "INBOX\Sent Items" (from apple mail). This is great as I send from 2x devices (mac and iPhone) and really needed a central sent items archive. If only Apple mail Notes and To Dos behaved now, Gmail would almost be a perfect solution.

  8. Aug 19
    05:15 PM

    I'll have a play and see about the saving sent on the server. I'm also curious to see about notes and to dos as it might make it easier to create to do items on the iPhone (I can't believe there are no tasks in iCal on the iPhone!).

  9. Aug 20
    11:36 AM
    bulge

    Perhaps Google fixed up the SMTP and sent items duplicates since more and more people with iPhones are using their service now. I played with Notes, which still behave badly with the All Mail folder. It seems that Apple Mail tries to write to the IMAP folder as you are entering the note. Gmail seems to keep versions of your notes in the "All Mail" folder (with your tip doesn't sync to Apple mail or iphone). Only the final version seems to stay in your inbox though. I have just been emailing myself things as a workaround to get map links and notes to my iphone. Would be nice to have Notes working though. To Dos seem to suffer from the same fate, with Gmail keeping different version of the to do in All Mail. I also get "Different versions of a To Do item have been found for the account..." messages occasionally. Something still is messing with it. I am the same as you, I tried using the INBOX prefix before, but didn't think it behaved. Now it seems to work as expected. Sure junk will will likely end up the All Mail folder in Gmail when you if you use Notes or To Dos... but at least it doesnt sync anymore! I rarely use the webmail interface for gmail, and with this tip, iPhone and Apple mail work great! Some IMAP IDLE "push" and happy times.

  10. Aug 20
    05:39 PM

    Cultured Code have just released a new version of Things (culturedcode.com/things/) for iPhone that syncs. Enables you to manage tasks and to dos on your Mac and on the iPhone. It's pretty and nice to use but still has a way to go before it will be really excellent.

  11. Sep 05
    07:10 AM
    Fred Avolio

    I've recently moved my email domain to gmail. I am using Mail.app as you are. I have the IMAP prefix set to [Gmail] and I have lots of mail folders (besides Trash, Sent, and Junk). The problem... if I move a message from the Inbox to mailbox Action it seems to me I end up with two copies of the message on my Mac. One copy under Actions and the other under All Mail. I know on Gmail, there is only one message. On my Mac there is two. I'm bothered by having two copies of every message (my All Mailbox has 6500 messages, most of them in various folders (Labels on Gmail). Current solution is to have the All Mail mailbox on my map be a link to the bit bucket. The consequence is I have to use the Google web interface if I want to Archive rather than Delete. Any thoughts or ideas around this? Anyone else who uses lots of mailboxes and doesn't like having 2 copies of everything?

  12. Sep 05
    07:23 AM
    Fred Avolio

    I may be in a minority in this. I have a bunch of mail boxes. I have the usual Inbox et al. plus project folders and mailboxes. This works fine. So I see them as Labels in Gmail ([Gmail]/accounting, [Gmail]/To do, [Gmail]/Project1, etc.) and as mail folders and mailboxes in Mail.app. The problem is will All Mail. All Mail has, of course, copies of all my mail. So, if I move something from Inbox to Project1, it gets labeled as Project 1 (no longer Inbox), but also is in All Mail. On Google, there is 1 copy of the mail. On the Mac there are now 2: 1 in the All Mail mailbox and one in the Project 1 mailbox. I have 6500 mail messages. I keep my Inbox mostly empty (2 messages in it right now). I do't want a duplication of every message. I think I have no solution except to do what I am currently doing: map All Mail (on the Mac) to /dev/null, so that the copy "works" and I only end up with 1 copy of the message on my Mac. Any other ideas? Anyone else bothered by having 2 copies of every message (on the Mac)?

  13. Sep 05
    07:57 AM

    Fred, this is exactly the reason why I am doing it the way I am suggesting here. If you specify INBOX as the IMAP prefix, you are essentially outside [Gmail]/All Mail and won't see the messages there. This means you don't have all the duplicate email issues. It's not perfect as you then can't "see" the Gmail Draft, Sent, Spam folders but I can live with that. If you send through Gmail's SMTP servers but store sent messages locally, you get a copy of sent in both places anyway. Hope that clears it up for you. And I hope Google does do something about it sometime soon : )

  14. Sep 21
    03:15 PM
    Gabe

    Yay! Thanks for this tip. Fixed up my work computer access to my GMail so that I don't download gigs of email.

  15. Sep 25
    11:52 AM
    drevet

    in the mail.app (2.0) advanced account settings I have the option to "automatically synchronize changed mailboxes". If I check this what will happen? And will this fix result in deleting all the duplicates currently saved on my hard drive or do I have to do that manually? thanks

  16. Sep 25
    12:57 PM

    Drevet, automatically synchronising changed mailboxes means, if you change a name for example, it will reflect on Gmail immediately without you needing to sync the account. Good question about the existing duplicates on your computer; to be honest, I'm not sure if they'll be removed. Maybe someone else knows the answer to that.

  17. Sep 25
    01:08 PM
    drevet

    So I possible solution would be to delete the entire account and then set it up again with the IMAP Path Prefix as Inbox

  18. Sep 25
    01:48 PM

    Well, actually, it seems that deleting an account in Mail doesn't actually delete the folders in the Finder. Probably changing the prefix to INBOX then synchronising the account should do it. Your emails reside in ~/Library/Mail (that's /Users/username/Library/Mail) so it's pretty easy to see if they've been removed or not.

  19. Sep 26
    02:55 AM

    I LOVE YOU! seriously, I've been loosing my head with the folders thing and the ONLY solution was to tweak the labels "INBOX/INBOX/whatever", that did it. THANK YOUUUUUUUU

  20. Sep 26
    04:09 AM

    ok I sent that e-mail too fast and realized something is not working now..... how do I delete messages from mail? I mean, when I delete one, it just archives it at Gmail... any other way?

  21. Sep 27
    03:49 AM

    Thanks for the tip Galen. This problem had been vexing me for some time. However having made the changes as you describe I can't see my Google Inbox anymore. All of my INBOX/A folders are present, but Mail doesn't see any Gmail that isn't in an INBOX/FOLDER. I feel like I've missed a step, do you have any idea what might be happening. There is mail in the Gmail inbox when I use the Web UI, and I've sent a test message.

  22. Sep 27
    04:15 AM

    Sorry, false alarm. I opened the Activity Monitor and mail seemed to be hung-up updating the caching directory for a bunch of the folders. I stopped those and it furiously worked away and my Inbox messages appeared.

  23. Oct 22
    12:59 PM
    David Kovar

    Greetings, So I've got a sort of related problem - Gmail via IMAP is *too* aggressive about de-duping. If you send an email message to a mailing list, the message never shows up in your folder for that mailing list. This means that you can't tell if the message made it out, among other things. It does show up in All Mail but, if you've unsubscribed from All Mail, you cannot see it. I'd really like to have it show up in the folder, or in Gmail terms, with the appropriate label on it. I can make this work by using a non-Google smtp relay, but then I need to find one that I can use from anywhere. -David

  24. Oct 28
    11:50 PM
    Ernst

    My brother suggested me this new feature of gmail http://lifehacker.com/5061419/gmail-labs-adds-advanced-imap-controls It lets me still use my sent and trash folder

  25. Oct 29
    08:48 AM

    Ernst, thanks for the heads-up. That's fantastic news. I'm going to try it out straight away and will report back.

  26. Mar 06
    04:59 AM

    Worked beautifully. Thanks!

  27. Jun 05
    01:55 AM
    Daryl Alexander

    This worked great, except I cannot delete messages from my inbox and have them removed from gmail server. Also I cannot get the folders to show up as labels on the gmail server all mail. Any ideas?

  28. Nov 20
    12:16 PM
    jimthing

    Gmail is a pain_in_the_backside with external clients, especially the pretty good Mail app on Mac. I worked on it for a whole weekend trying to get it to work outside of the web interface, on both mac and iphone, both using/not using the archiving email facility. The result: give up! The 6 permanent folders (except inbox) are bunched together in the sidebar of Mail, and DO NOT go next to the other email address mailboxes (sent/drafts/trash) even when put there (via "Mailbox" menu, then "Use This Mailbox For"), because of the stupidly conceived Google guidelines on setting prefs for Gmail in Mail to work properly. Even ignoring them and doing any of the above WILL NOT make it work any better, due to the "archiving vs. deleting" idea Google insist you have to use like it or not. I already had MobileMe family pack which works like a breeze, even though it costs a few quid, it does come with extra functions, and makes the mac-to-iphone syncing easy, though they are a bit mean with the amount of space given for the money paid (1x20GB: main account/4x5GB sub accounts, for £90/year) compared with Google's free 7.5GB email, and infinite Picasa storage. However I wanted another separate IMAP company as a backup in case MM was down for some reason, and also to use for subscriptions/junk stuff. ...looks like Yahoo (or someone else) here I come, unfortunately, as Gmail *could* have been really good. If this is the integration to expect in the future with their 'cloud' computing, then I for one won't be using it.

  29. Jan 01
    01:18 AM
    gunawan

    Galen, i tried the above solution but it did not work. When you mention INBOX in the path of IMAP, did you refer to the INBOX of APPLE MAIL or GMAIL? And when you mention INBOX/A Folder, what do you mean by that?

Comments