[Note: With the release of OS X 10.9 Mavericks, this article is completely out of date. If you’re running Mavericks, please do not follow these instructions! My latest advice for dealing with Gmail in Mail can be found in "Take Control of Apple Mail." Quoting from that book:
When Mavericks was first released, Mail had some appalling bugs that made Gmail almost completely unusable for anyone who had followed [the steps in this article] (which, remember, were previously the way to prevent misbehavior). In later updates [to Mavericks], Apple fixed a number of bugs so that people who had changed their Gmail settings in the way I suggested wouldn’t suffer (much). Be that as it may, the way Mail in Mavericks handles Gmail accounts is so much different from Mail in earlier versions of Mac OS X that, for all practical purposes, those 21 steps to “bliss” are now irrelevant. In fact, you’ll now get the best results in Mail if you leave most of Gmail’s settings at their defaults!
For information on even further changes to Mail and Gmail with the release of OS X 10.9.2, see "Mail Improvements in OS X 10.9.2," 25 February 2014.]
For the past few months, I've been unusually happy with my overall email situation. I won't say it's perfect, but it's way better than it has been in the past - much better even than when I was running my own mail server on my own Xserve, a setup that I would have thought offered me the ultimate in flexibility and power. The ingredients I now rely on - Google's Gmail (via Google Apps Standard Edition, which lets me use my own domain name), IMAP, and Apple Mail - provide the sweet spot that best suits my needs. However, as I discovered through a considerable amount of trial and error, the recipe needed to combine all these ingredients into an edible dish was anything but obvious. For those who have had less-than-satisfactory experiences with their email providers and software (especially Gmail and Apple Mail, respectively), I'd like to share how I achieved my personal state of email satisfaction.
Well, that's what I intended to do, anyway. The more I wrote, the more I realized how many aspects of the IMAP/Gmail/Mail universe are unclear or confusing, as evidenced by the many email messages I've received on those subjects, and as feedback to my books ("Take Control of Apple Mail in Leopard" and "Take Control of Spam with Apple Mail") and my Macworld articles on the topic. So, what I thought would be a straightforward article has turned into a manifesto. (That means it's quite long, and somewhat opinionated - fair warning!) And, I admit it: I've written it for a largely selfish reason, which is to save myself from having to explain this information repeatedly in email messages! But I do hope you'll find it interesting and helpful if you've ever struggled with the combination of IMAP, Gmail, and Mail.
I want to be clear about one thing right up front: my method works well for me because it matches the way I use, and think about, email. If you're accustomed to using or thinking about email in a much different way, your mileage may vary - and you may find my setup unworkable. In particular, if you expect Mail (or any IMAP client) to work just like Gmail's Web interface in the way it handles archiving, some of what I describe here may disappoint you. Email management is a matter of, among other things, habit and taste. So I don't presume to say this system will work for everyone, or that it doesn't have limitations.
That warning aside, I'm going to - eventually - explain how I do what I do in what I hope is a clear, systematic way. In order to provide context for the actual steps to take, I'm going to begin with detailed background information about IMAP generally and the somewhat nonstandard ways Mail and Gmail handle it. Feel free to skip the background stuff and jump ahead to "How to Configure Everything for Maximum Happiness," but even highly knowledgeable users may find this material enlightening.
IMAP -- I've been extolling the virtues of IMAP (Internet Message Access Protocol) for well over a decade, and although this protocol has become much more popular during that time, it's clear that a lot of people still don't understand what it is and why it's superior to POP (Post Office Protocol). Even in the past couple of months I've heard more than one person dismiss IMAP using arguments that reflect basic misunderstandings. So, without giving a complete, detailed technical overview of IMAP, let me lay out the basics.
POP and IMAP are both methods of retrieving messages from a mail server. (In fact, many mail servers support both protocols, enabling you to access the same messages in either way.) The most common way to explain the difference between POP and IMAP is this: With POP, you download all your messages to your computer, whereas with IMAP, all your messages remain on the server. That's more or less true, but it overlooks several important points.
First, the fact that IMAP stores messages on the server is often taken to imply that it's equivalent to the POP option to download messages but leave them on the server. But it's much different. In the first place, IMAP servers, unlike POP servers, can keep track of flags for each message, indicating things like which messages have been read, forwarded, or replied to. With POP, your local email client has to track this information. That means if you download a bunch of messages on computer A using POP but leave them on the server, and then switch to computer B, you can still download the messages again, but they'll all appear to be unread - computer B won't know which messages you've seen, filed, or otherwise dealt with, because that information isn't kept on the POP server.
Second, speaking of filing, another key difference between POP and IMAP is that POP has just one mailbox - your inbox - on the server, whereas an IMAP server can have any number of mailboxes. So, if you check your email on computer A and move a certain message to your Read mailbox, and then check your email on computer B, that message will appear in the Read mailbox there as well.
Third, I would like to put to bed, once and for all, the biggest IMAP myth of all time. It is not the case that when you use IMAP, you can access your email messages only when you're connected to the Internet! I want to be crystal clear about this. If you use IMAP, you absolutely can have local copies of all your email messages, in their entirety, on your computer, and you can read, search, file, and do anything else you want to do with those messages even if you have no Internet connection at all - just as you can when you use POP. It is true that in some IMAP clients, this behavior isn't automatic and requires a few clicks to set up, but there's nothing about IMAP that inherently prevents messages from living both on your hard disk and on the server. In fact, the most common configuration of IMAP these days - and the default configuration in Mail - is to have one's local mail store exactly mirror the server's mail store, such that changes made on one side are reflected automatically on the other side. File a message locally, it's filed on the server; delete a message locally, it's deleted on the server, and so on.
In short, although both POP and IMAP can get email messages from a server onto your screen, IMAP provides a much broader and richer set of options. And, as a bonus, you can use IMAP as a sort of rudimentary email backup. Even if your disk crashes or your computer is stolen, you'll still have a copy of all your messages on the server. (The reverse is also true: if your IMAP provider should lose any of your messages, you'll have a local backup.) One of the things I've appreciated most in my years of using IMAP is that I can switch email clients, computers, or even operating systems without giving the slightest thought to exporting or importing email messages (and all the grief that can involve). I simply enter my account credentials in the new software and (not counting the time it takes to download new local copies of my existing messages) I'm all set.
IMAP does have a couple of downsides, which may or may not be significant to you. First, most IMAP servers impose a storage quota on each user. If that quota is fairly low (say, 1 GB), you could run out of space for all your messages, forcing you to move some off the server to a mailbox that's stored only on your computer. (Gmail deals with this problem by setting generous quotas, which increase in size every day, and by offering even larger quotas for a modest annual fee.) Also, if you have a slow Internet connection (such as a dial-up or GPRS mobile connection), IMAP can be slower than POP because your client must explicitly ask the server for each message you want to download, rather than simply downloading whatever new messages appear in the inbox automatically. (With fast Internet connections, this method of asking for and receiving data isn't a problem.)
Mail and IMAP -- Although IMAP is wonderful in theory, all IMAP servers are not created equal. Some have features that others lack, or use nonstandard approaches to providing one capability or another. In addition, one's experience of using IMAP is always mediated by client software (either software you run locally on your computer or software that provides a Web-based interface to the IMAP server). Unfortunately, many IMAP clients also take certain liberties with the IMAP protocol, with the result being that some of that wonderfulness is lost from the user's perspective. Apple Mail, which is a much better IMAP client than some, nevertheless has a handful of quirks in its handling of IMAP that can drive one to distraction. If you combine Mail's IMAP oddities with those of a less-than-standard IMAP server - Web Crossing, I'm looking at you - you could easily have unpleasant experiences that may lead you to the erroneous conclusion that IMAP itself is buggy or poorly designed. (Later on, I'll get into the even weirder ways that Gmail deals with IMAP.)
Here are some of the problematic ways in which Mail handles IMAP:
Mail has had, for quite some time, odd performance problems when communicating with at least some brands of IMAP server. Frequently, the simple act of checking one's mail takes an inordinately long time, sometimes because Mail, in the background, is busy synchronizing a bunch of mailboxes and only gets around to checking your inbox when it has completed a number of other tasks. For the same reason, it's not uncommon for Mail to take a long time to quit. It looks like nothing is happening, but in fact it's trying (clearly, not hard enough) to log out of certain accounts, finish syncing mailboxes, or do other last-minute cleanup tasks such as deleting old messages. Some Mail users never encounter these problems, but if you're unlucky enough to use an uncooperative IMAP server - and especially if you use Mail for several accounts at once - Mail can appear to be quite sluggish when using IMAP.
IMAP supports server-side searching (say that five times fast), but Mail doesn't. Mail relies on a Spotlight index of (the locally cached copies of) all your messages to deliver search results. For all the hype Apple has heaped on Spotlight, I (and many other Mac users) have found it to be a drag, even in Leopard. It's often slow and frequently yields incomplete results. And even though system-wide Spotlight searches are reasonably capable, Mail's pathetic search interface has no support for Boolean operators or proximity searches, and can't search hidden headers, HTML source, or any other message components that are normally invisible in the user interface. This is a pity, because IMAP itself supports all this - if Mail let you tie into the server's existing search capabilities, you might get faster, more accurate, and more flexible results.
With most IMAP clients (including, notably, Entourage), you can subscribe to particular mailboxes in a given IMAP account, meaning only those mailboxes show up in the client's mailbox list. If you have old mailboxes full of archived mail, for example, you can opt not to subscribe to them, so your software never has to waste time syncing them, searching them, or whatever. Mail doesn't do subscriptions - it just shows you all your mailboxes, all the time. If you choose Get Account Info from the pop-up Action menu at the bottom of the sidebar in Mail and click Subscriptions, you might think you'll see a list of mailboxes to which you can subscribe or unsubscribe. But usually this list is blank; it shows only mailboxes in "Public" or "Shared" mailboxes on the server, if such mailboxes exist.
When it comes time to delete a message, the IMAP procedure is for your client to set a flag on the server that marks the message as ready for deletion. Then, at some later point, your client (manually or automatically) tells the server to "expunge" the mailbox - that is, actually delete all the messages in it that are marked for deletion. In the meantime, the client can hide the marked-for-deletion messages, or show them in a strikethrough style, or designate them as almost gone in some other way. Mail, instead, tries to replicate the Finder's model for deleting files. When you delete a message, Mail appears to move it to a Trash mailbox (which, confusingly, may be either local or on the IMAP server, depending on settings that aren't obvious). Then, to delete the message for good, you choose Mailbox > Erase Deleted Messages > Account-Name. However, in reality, what happens when you delete a message in Mail is the following. First, Mail makes a copy of the message in your Trash mailbox. Then it marks the existing copy for deletion, making it invisible in the process. As far as your IMAP server is concerned, the message is still where it always was, only with a new flag. When you choose Erase Deleted Messages, Mail expunges the original copy and deletes the copy in the Trash mailbox. You can fiddle with Mail's preferences to treat deleted messages in a more standard IMAP manner, but it takes some doing.
By convention, most IMAP servers and clients set aside special mailboxes for Drafts, Sent, Junk, and Trash, but the names used for each of these mailboxes differ from one program to another. Mail lets you designate any IMAP mailbox to serve any one of these purposes (by using commands on the Mailbox > Use This Mailbox For submenu). However, after you set up a new IMAP account, the first time you send a message, Mail looks for a mailbox named Sent Messages to store a copy in. If it doesn't find that mailbox, it creates it. (Similarly, when you first save a draft or delete a message, Mail looks for a Drafts mailbox or Deleted Messages mailbox, and if it doesn't find one with that exact name, it creates one. And, if you use Mail's built-in junk mail filtering to move suspected spam to a server-based Junk mailbox but there's no mailbox there named Junk, Mail creates one.) So, for example, even if you already had a mailbox on your IMAP server called Sent, which you wanted to use to hold sent messages, and even though Mail's mailbox list contains a mailbox called Sent, what happens behind the scenes is that Mail creates a new mailbox on the server called Sent Messages, displays that mailbox using the label "Sent," and uses that to store sent messages - while, at the same time, displaying your existing Sent mailbox separately in the mailbox list! This is incredibly confusing, especially when I have to explain to someone that their Sent mailbox isn't really their Sent mailbox, and that to fix the problem, they have to select the Sent mailbox listed under their IMAP account name, choose Mailbox > Use This Mailbox For > Sent, and then delete the Sent Messages mailbox that will suddenly, mysteriously appear where Sent used to be. Gah!
The other special attribute of the Drafts, Sent, Junk, and Trash mailboxes is that most IMAP clients (including Mail) let you choose whether you want to store their contents locally only, or on the server (with a local copy). By default, Mail stores all these items except Junk on the server. Personally, I've never seen the point in offering the choice; it seems to me that it would be simpler if these mailboxes were always stored on the server and cached locally, like the rest. Be that as it may, your choice of which of these items are enabled, along with the names used for each mailbox as described in the previous point, can have a big effect on how Mail behaves, but it's complicated for non-expert users to decode what Mail is doing or how to set it up optimally.
Mail can, and usually does, make as many as four simultaneous connections to any given IMAP server. In theory, this should provide faster performance by enabling Mail to do several different things at once (such as copying messages from one mailbox to another while refreshing the contents of your inbox). However, sometimes all those connections actually slow Mail down, especially when you're checking multiple IMAP accounts at the same time. Moreover, Mail sometimes insists on keeping all four of those connections open even when they're not actively doing anything, and can be very slow to close connections that are stuck or non-responsive for a period of time. This behavior has special implications for Gmail, as I'll explain shortly - and unfortunately, Mail offers no user interface (as some other IMAP clients do) to set the maximum number of concurrent connections or whether to keep those connections perpetually open.
Gmail and IMAP -- Gmail started out as a Web-only interface for email. Since Google had complete control over how email was processed, stored, and presented, they decided to handle it all in the way that made the most sense for their existing indexing infrastructure and for (what they perceived as) users' needs. The basic idea was that a good search engine should make mailboxes obsolete - just toss everything in one big mailbox and do a quick Google search to find whatever you're looking for.
Later, a refinement appeared in the form of user-defined labels. By labeling (or tagging) messages, you could indicate that many seemingly unrelated messages shared something in common, thereby letting you quickly display a group of messages that would never otherwise appear together in a search. Gmail lets you apply as many labels as you want to each message, which is a much different approach to categorization from using mailboxes (since each message can appear in only one location in a mailbox hierarchy).
Users flocked to Gmail for a variety of reasons, not the least of which were its cost (free), its large storage space for email, and its accurate spam filtering. But because many users preferred to use their existing email software, rather than a Web browser, to access their email, Google added a POP interface to Gmail. Obviously, when downloading messages via POP, you lose Gmail's search and labeling features (though you can also choose to leave all the messages on the server as well, to give yourself another way to access them). Through Google Apps, Google even made it possible to use Gmail with one's existing email address, so that users could take advantage of all the nifty Gmail features without having to switch domains or addresses.
Gmail eventually added yet another major feature that many people, including me, had been dying for: IMAP access. For me, the benefits of IMAP outweighed the benefits of Gmail, but I was thrilled when I learned I could get both. Now, I could have all the IMAP goodness (such as freely switching between clients and platforms) along with all the Gmail goodness (excellent spam filtering, a great Web-based interface for when I'm away from Mail, and most of all, freedom from having to constantly futz with my existing and increasingly finicky mail server).
To pull this off, Gmail's paradigm of using multiple labels to categorize messages (with no capability to create mailboxes) had to be reconciled with IMAP's assumption that you can create as many mailboxes as you need. Their solution was to map labels to mailboxes and vice-versa. So, if you move a message in your IMAP client to a mailbox called Stuff, you'll see, in Gmail's Web interface, that the message has a label called Stuff. If, using the Web interface, you apply the labels Apples, Oranges, and Mangoes to a message, then, in your IMAP client, you'll see three copies of that message - one each in the Apples, Oranges, and Mangoes mailboxes. It's not a perfect solution, and it's certainly nonstandard in that IMAP normally stores only one copy of each message - but it's a reasonable design, as far as it goes.
Apart from that unusual system, Gmail's IMAP implementation is weird (at least, from the Mail user's perspective) in other ways. For example, Gmail limits each account to 10 simultaneous IMAP connections, not counting access via the Web. That sounds like a lot, and for many people it isn't a problem. But because Mail is so greedy in this regard - opening, as I mentioned earlier, as many as four connections, and keeping them open - the practical upshot is that you're limited to running just two simultaneous copies of Mail (say, one on your desktop Mac and one on your laptop). Even more aggravating, if I have Mail open on my Mac and my iPhone turned on (whose version of Mail also uses multiple IMAP connections), I've hit my limit right there. If I then open Mail on any of the other Macs I might be using at any given time, that puts me over the limit with just three IMAP clients - Gmail automatically blocks the connection to the most recently used copy of Mail until the total number of connections drops below 10. And, because Mail can take such a very long time to let go of its connections, this may mean a wait of up to 10 minutes (Gmail's IMAP timeout period for inactivity) even after taking one of my copies of Mail offline. (And before you ask, no, this has nothing to do with Mail's "Use IDLE command if the server supports it" checkbox - that's another whole can of worms.) A Gmail engineer who contacted me expressed hope that this problem will be addressed in a future version of Mail.
In addition to the limit of 10 connections, Gmail watches for what it considers excessive activity - such as downloading all your IMAP messages several times in a day. (The need to download all one's messages occurs, for example, when setting up Mail on a new computer or re-syncing Mail's entire database after data corruption.) Although the exact algorithm Gmail uses to determine what's excessive is not publicly known, I've personally surpassed whatever the metric is when, for one reason or another, I had to download all my IMAP messages just twice in one day, not counting my usual IMAP access. When you surpass this mysterious download limit, Gmail locks you out of all IMAP access for up to 24 hours - an extremely unpleasant occurrence.
There are other limitations and issues with Gmail's IMAP support, too, some of which I mention later in connection with Mail.
Mail and Gmail and IMAP -- Mail, by itself, has some issues with any IMAP server, and Gmail, as a nonstandard IMAP server, has some issues with any IMAP client. When you put the two of them together, you can run into some interesting behavior. For example, Gmail's one big mailbox that holds all your messages is called, cleverly enough, All Mail. (This includes copies of messages you've sent, even though they're also available by using the Sent label/mailbox, as well as spam messages and deleted messages in your Trash.) This mailbox, along with all your other labels-as-mailboxes, syncs locally to Mail when you access Gmail via IMAP. As a result, if you (like most IMAP users) have filed all your messages into various mailboxes, Mail would download at least two copies of every single message - the one in All Mail and an additional copy for each label the message had. Of course, this poses no problem to IMAP clients that can unsubscribe from particular mailboxes, but oops! Mail can't do that. This was one of the biggest headaches I had in my early days of using Gmail with Mail, and in just a bit I'll explain how to overcome this problem.
A further complication of All Mail is that Gmail has a concept of "archiving" messages, which means moving them out of your inbox but not necessarily giving them another label. The result of this is that they appear only in the All Mail mailbox. If you prevent All Mail from appearing in Mail (as I recommend and describe ahead), this means you won't see any messages in Mail that you previously archived there using Gmail's Web interface but which lack any other label. Nor does Mail (or IMAP generally) have anything precisely equivalent to Gmail's Archive button - that is, a way to move messages out of the inbox without explicitly putting them somewhere else. This is one of those examples of needing to think about email a certain way: if you're committed to the archiving paradigm, my suggestions won't suit you. However, I present a possible workaround ahead in my detailed list of instructions.
Another source of confusion was what to do with the special mailboxes Drafts, Sent, Junk, and Trash - specifically, whether or not (in view of the odd label/mailbox behavior and the duplication of messages) to store their contents on the server. Google's Web site provided suggested settings, and some other Web sites I read offered conflicting advice. What I discovered was that with Google's recommended Mail settings, every time you send a message you get two copies - one stored in a local Sent mailbox and the other stored in Gmail's Sent Mail mailbox on the server (and, of course, synced locally too)! Only after experimenting with a variety of settings myself and observing the results (in multiple accounts, on multiple Macs) did I arrive at a combination that gave me approximately the behavior I expected, even though it contradicts Google's advice.
And finally, I'm accustomed to having all my mailboxes be part of a single hierarchy within any account. But Gmail wants to display, along with all my regular labels-as-mailboxes, another mailbox called [Gmail] that contains my Drafts, Sent, Junk, and Trash mailboxes - plus All Mail and Starred (equivalent to Mail's Flagged status). According to Google, that unfortunate organization was necessary to support certain nonstandard IMAP clients and work around problems with supporting multiple languages. It offends my aesthetic sensibilities, but I wasn't happy with the workaround I discovered for getting rid of the [Gmail] folder either.
How to Configure Everything for Maximum Happiness -- Hey! Everyone who blew off the last few sections because you weren't interested in background info! This is where you jump back in. I'm going to explain, top to bottom, how to configure everything on both the Gmail side and the Mail side to work the way it does for me, which is to say as good as I can figure out how to make it - and that's pretty darn good in my book. I'm also going to mention a few things that, even in this shiny new world order, aren't quite right - and then wrap up with some observations about the pros and cons of using this method for handling email.
Steps 1-5 are basic Gmail and IMAP configuration. You may have done some of these steps already; if so, please read them over anyway to be sure you've set up things the same way I recommend, and if not, make any necessary changes as you go.
(1) Get a Gmail account. I won't walk you through the process because it's fall-off-a-log simple. However, I do want to reiterate that if you want to use your own, existing domain name with Gmail, you need to go through an entirely different setup process to set up a free Google Apps Standard Edition account. This involves changing some of the DNS settings for your domain name to point to Google's servers. It's not hard, and Google offers clear, detailed directions. But be aware that your Google Apps Gmail account is completely separate from any existing Gmail account you may have - you can't simply assign a new email address to your current account. Apart from the initial account sign-up procedure, all the steps that follow are, with a sole exception (noted ahead), identical for either type of account.
(2) Log in to your Gmail account.
(3) At the top of the window, click the Settings link.
(4) Click the Forwarding and POP/IMAP link.
(5) Select Enable IMAP and click Save Changes.
Steps 6-8 configure a special Gmail Labs feature to minimize IMAP annoyances in Mail:
(6) Only if you're using Google Apps, make sure Gmail Labs is enabled. To do this, make sure you're logged in to Gmail as an administrator of your domain, and click the Manage This Domain link at the top of the Gmail window. Then click Domain Settings. On the General tab (displayed by default), make sure both of the following boxes are checked: Automatically Add New Services When They Become Available and Enable Pre-Release Features. Click Save Changes at the bottom of the window. Then log out of Gmail, log back in, and once again click the Settings link.
(7) Click the Labs link, which should appear under "Settings" to the right of "Web Clips." Scroll down until you see Advanced IMAP Controls and click the Enable checkbox next to it. Then click Save Changes.
(8) Click the Labels link under "Settings." Now, uncheck the Show in IMAP checkboxes for Starred and All Mail. This is essentially the same thing as unsubscribing from these two mailboxes, except that you do it on the server side instead of the client side - it applies to all clients. Crucially, this step avoids having the All Mail mailbox, with its duplicates of every single message you send and receive, clutter up Mail.
As I explained earlier, the downside to this approach, for those who like to use Gmail's Archive button to remove messages from the inbox without putting them in another mailbox, is that you can no longer see archived messages in Mail unless they also have some other label. I never used this archiving method - for me, every message has at least one label (or is in a particular mailbox) - so this problem didn't affect me. But if you're accustomed to Gmail's archiving, you may find that you get equally good results by creating a different catch-all mailbox in Mail, such as "Filed," and simply moving all messages to that mailbox that you'd otherwise archive. Then, in Gmail's Web interface, you can select all the messages in All Mail without any other label and apply the Filed label, which makes them appear in Mail's Filed mailbox. It's not exactly the same as archiving, but it's reasonably similar.
(9) Once again click the Forwarding and POP/IMAP link. This time, check a new setting that was added by enabling the Advanced IMAP Controls. If it's not already selected, select Immediately Expunge Messages When I Mark Them Deleted in IMAP (under "Auto-Expunge") and click Save Changes.
Steps 10-15 set up your Gmail account in Mail:
(10) Open Mail, choose Mail > Preferences, click the Accounts button on the toolbar, and click the + (plus) button at the bottom left.
(11) Enter your name, your full Gmail address, and your Gmail password.
(12) Extremely important: uncheck Automatically Set Up Account, and click Continue. (If you leave that box checked, Mail sets up your account as a POP account, which is not what you want.)
(13) On the Incoming Mail Server screen, choose IMAP from the Account Type pop-up menu. Enter a description of your choice, change the Incoming Mail Server field to imap.gmail.com, make sure the User Name field includes your entire Gmail address, and confirm that your password is filled in. Click Continue.
(14) On the Outgoing Mail Server screen, once again enter a description of your choice, and check Use Only This Server. All of the other settings should already be correct - smtp.gmail.com in the Outgoing Mail Server field, Use Authentication checked, and your user name and password filled in.
(15) Click Continue, review your information, and click Create. Give Mail a few minutes to download your existing messages from Gmail and create mailboxes corresponding to your Gmail labels.
Finally, Steps 16-21 enable Mail to deal correctly with Gmail's special mailboxes. Note that you need not explicitly make any changes to the checkboxes in the Mailbox Behaviors view of Mail's Accounts preference pane, but following these steps results in all four of the "Store messages on the server" boxes there being checked.
(16) Look in the mailbox list in Mail's sidebar. You should now see, at the bottom, an account with whatever description you specified for your Gmail account in Step 12. Click the disclosure triangle next to it to display its contents. You'll see, at minimum, a white mailbox (white signifying that the mailbox itself contains no messages) labeled [Gmail], along with mailboxes representing any other labels you've created. Click the disclosure triangle next to [Gmail] to display its contents, which should at this point be Drafts, Sent Mail, Spam, and Trash. (Had you not performed Steps 6-8, you'd also see Starred and All Mail here.)
(17) To tell Mail to use Gmail's Sent Mail mailbox as the Sent mailbox for this account, select Sent Mail under [Gmail] and choose Mailbox > Use This Mailbox For > Sent. The Sent mailbox then disappears from under [Gmail] and reappears near the top of your mailbox list as a sub-mailbox with your Gmail account name under the main Sent item. (Here, and in the steps that follow, note that the special mailboxes appear as sub-mailboxes only if you have at least one other account set up in Mail; otherwise, they'll be the only Drafts, Sent, Junk, and Trash mailboxes that appear.) If, after you do this, a Sent Messages mailbox appears at the bottom of your mailbox list in your Gmail account, select all its contents (if any) and drag them to your main Sent mailbox at the top. Wait a few minutes for the transfer to complete, and then select the Sent Messages mailbox, choose Mailbox > Delete Mailbox, and click Delete. I want to reiterate that this advice differs from what Google suggests, but trust me: this is the way you want to do it, to avoid having duplicate sent messages in different mailboxes.
The result of doing this will be that, whether you send a message from Mail or from the Gmail Web interface, a copy will be stored in the same mailbox - the one Mail calls Sent, and Gmail's Web site calls Sent Mail. Note: Do not CC or BCC yourself on messages you send via Gmail. (That is, choose Mail > Preferences, click Composing on the toolbar, and make sure Automatically Cc/Bcc Myself is unchecked.) It's not necessary, because Gmail saves a copy automatically, and you'll only end up with a duplicate. Note also that Gmail displays in your Sent (Mail) mailbox any spam messages you may have received that were forged so that they appear to have come from your own address! Weird and annoying, but if you delete all your spam messages regularly, nothing to worry about - they disappear from Sent too.
(18) Next comes Drafts. As you did with Sent, select Drafts under [Gmail] and choose Mailbox > Use This Mailbox For > Drafts. The Drafts mailbox then disappears from under [Gmail] and reappears as a sub-mailbox under the main Drafts item. Now, whether you save a draft in Mail or in the Gmail Web interface, it'll show up in the same (Drafts) mailbox. (If you were to skip this step, the next time you composed a message, Mail would create a new, hidden Drafts mailbox that would appear, in Gmail, as a label called [Imap]/Drafts. That introduces yet another layer of complexity I prefer to avoid.) Once again, if, after you do this, a Drafts mailbox appears at the bottom of your mailbox list in your Gmail account, select all its contents (if any) and drag them to your main Drafts mailbox at the top. Wait a few minutes for the transfer to complete, and then select the Drafts mailbox under your Gmail account at the bottom of the list, choose Mailbox > Delete Mailbox, and click Delete.
But, you need to be aware of yet another goofy thing about Gmail and Mail when it comes to drafts. Normally, when you compose a message in Mail, it saves a copy in your Drafts mailbox automatically every 30 seconds as well as whenever you manually click Save as Draft. Each time a new draft is saved, Mail deletes any previous draft of that message (without moving it to a Trash mailbox), so you see only one draft in your Drafts mailbox. But Gmail-over-IMAP behaves differently. When you compose a message in your Gmail account, Mail still saves a copy of your work in progress every 30 seconds, and still deletes any previous draft. However, instead of the previous drafts disappearing altogether, they all show up in your Trash mailbox. As a result, if you spend 10 minutes writing a message in your Gmail account in Mail, you could see 20 drafts of that message in your Trash mailbox! This behavior isn't harmful - just empty your Trash every so often, or use Mail's preferences to set up automatic Trash emptying. But it can be quite a shock to see tons of draft messages in your Trash that you never explicitly created or moved there! A Gmail developer told me that this strange behavior was necessary to work around a bug in certain IMAP clients, and that they may be able to find a better solution in the future.
(19) Now on to Trash. Just as in the last two steps, select Trash under [Gmail] and choose Mailbox > Use This Mailbox For > Trash. The Trash mailbox then disappears from under [Gmail] and reappears as a sub-mailbox under the main Trash item. Now, whether you delete a message in Mail or in the Gmail Web interface, it'll show up in the same (Trash) mailbox. If a Deleted Messages mailbox appears at the bottom of your mailbox list in your Gmail account, select all its contents (if any) and drag them to your main Trash mailbox at the top. Wait a few minutes for the transfer to complete, and then select the Deleted Messages mailbox, choose Mailbox > Delete Mailbox, and click Delete.
(20) Finally, the Junk mailbox. Unlike the other three special mailboxes, Mail doesn't store Junk messages on the server by default, the assumption being that there's no need to waste space on the server with messages you don't want in the first place. But Gmail automatically applies a Spam label to all suspected junk mail, which has the effect of keeping it out of your inbox and putting it in a Spam mailbox when viewed from an IMAP client. In other words, spam is already on the server (and, along with all your other IMAP mail, synced locally to your Mac too), so the question becomes how you want to view and manage it. You have two approaches here, both perfectly valid.
One option is to leave the default settings in place. The result would be that any messages Gmail flags as spam would appear (only) in the Spam mailbox under [Gmail] in your Gmail account. You could then review and delete those messages at your leisure - either in Mail or in the Gmail Web interface. However, if Mail's built-in Junk Mail filter were to catch any additional spam messages from your Gmail account (which does happen from time to time), those messages would either be marked as Junk Mail and left in your inbox, or moved to a Junk mailbox in the "On My Mac" (local) portion of your mailbox list, depending on your preferences. In other words, you'd have to look in two places for suspected junk mail instead of one. On the other hand, since Mail's Junk Mail filter is less accurate than Gmail's, it could be that most of what Mail flags as spam are false positives. If so, you may prefer to use this approach, in which the likeliest false positives are all together in a relatively short list that's easy to scan, instead of mixed in with all the other messages that are more likely to be spam.
The other option, and my personal preference, is to go ahead and let Mail treat Gmail's Spam label/mailbox as the Junk mailbox for that account. This has no effect on the number of spam messages downloaded to your computer. What it does change is putting all the junk mail in one place and eliminating an extra mailbox - so I like it for the sake of tidiness. In addition, it means that whenever Mail marks a message as spam by moving it to the Junk mailbox, it also tells Gmail that the message is spam, helping to improve Gmail's spam filtering for all users at the same time Gmail helps to improve Mail's junk mail filtering by teaching it which messages it thinks are spam.
To set up the Junk mailbox in the way I prefer, first choose Mail > Preferences, click Junk Mail, and make sure the Enable Junk Mail Filtering box is checked. Under "When junk mail arrives," if the top radio button (Mark As Junk Mail, but Leave It in My Inbox) is selected, instead select Move It to the Junk Mailbox and click Move. Next, go back to the main Mail window, select Spam under [Gmail], and choose Mailbox > Use This Mailbox For > Junk. The Spam mailbox then disappears from under [Gmail] and reappears as a sub-mailbox under the main Junk item. Now, whether Gmail flags a message as spam, or Mail's Junk Mail filter does, or you manually mark a message as spam in either place, it'll show up in the same mailbox - the one Mail calls Junk, and Gmail's Web site calls Spam. If a Junk mailbox appears at the bottom of your mailbox list in your Gmail account, select all its contents (if any) and drag them to your main Junk mailbox at the top. Wait a few minutes for the transfer to complete, and then select the Junk mailbox, choose Mailbox > Delete Mailbox, and click Delete.
(21) That's (pretty much) it. At this point, your mailbox list should show, under your Gmail account, an empty mailbox called [Gmail] (though it'll contain a mailbox called Spam if you went for the first option in Step 19), along with mailboxes representing your Gmail labels. You can simply ignore the [Gmail] mailbox.
But maybe you can't ignore [Gmail]. Maybe its very presence in your mailbox list offends your sense of order, since it serves no purpose now. Can you get rid of it? Well, you can, but you may find the consequences of doing so even more unpleasant.
To get rid of [Gmail], tell Mail to treat the [Gmail] mailbox, rather than your inbox, as the root of your IMAP account. To do this, choose Mail > Preferences, click Accounts on the toolbar, and select your Gmail account in the list on the left. Click Advanced, and in the IMAP Path Prefix field, type [Gmail]. Then close the Preferences window and click Save. What happens at this point is that [Gmail] disappears - yay! But something else disappears, too: the rest of your Gmail mailboxes! With this configuration, Mail can display only mailboxes that are in the [Gmail] hierarchy. So, let's say you create a new mailbox in Mail called Archives. When you go to the Gmail Web interface, you'll see a new label called [Gmail]/Archives! Only labels that begin with [Gmail]/ will show up as IMAP mailboxes in Mail (or any other IMAP client). This won't affect your Drafts, Sent, Junk, and Trash mailboxes because they were already under [Gmail], but it will mean that if you had messages in any other mailboxes, you'll have to manually relabel them in Gmail in order to make them show up in Mail - and you'll have to live with every Gmail label starting with [Gmail]/. Personally, this bothers me more than having an empty [Gmail] mailbox, but you can do it if you want.
Further Considerations -- Now then. Let me explain what we have at this point. Your email arrives at Gmail's servers and gets filtered for spam automatically. You can then check your email in Mail (or in any other IMAP client, on any computer), or via the Gmail Web interface, and no matter how you look at it, you'll always see the same messages, with the same status (read/unread, replied to, etc.), in the same location (mailbox or label). You have tons of email storage space, access to a boatload of optional (and sometimes experimental) Gmail features, and you're not paying a cent for it.
One thing I love about using Gmail for mail is server-based rules (which Gmail calls filters). To set up a filter, just go to the Gmail Web interface, click the Create a Filter link next to the search field at the top of the window, and follow the instructions. Although Gmail's filters are less sophisticated and flexible than Mail's, I've been able to replicate about 90 percent of the functionality I had with Mail's filters (which I then deleted). Not only does this make Mail snappier by giving it less to do, it means that if I access my messages on the Web, on my iPhone, or in another client, they're already (mostly) presorted into the mailboxes of my choice, and my inbox isn't cluttered with nonessential mail.
Because your mail is hosted by Google's massive server farm, it's not subject to the kinds of problems that could affect mail hosted on a single server (like my Xserve) and is somewhat less vulnerable to outages than with most email providers. But Gmail has had a few (well-publicized) outages (see, for example, "Gmail Outage Marks Sixth Downtime in Eight Months" at PC World from February 2009). Some of these outages have lasted an uncomfortably long time, and they could potentially happen again. Of course, any email provider can have outages - that goes for MobileMe (see "MobileMe Mail and Gmail Go Down Simultaneously," 2008-08-11), Fastmail.fm (see Glenn Fleishman's blog post "No Longer Recommending Fastmail.fm" from August of 2006), and your own server too. My own feeling on the matter is that I'd rather have one of the world's largest Internet companies worrying about my email outage than having to deal with it myself (or leaving it in the hands of a smaller, less-capable email provider), and since I have several other email accounts I can use as a backup, I don't lose too much sleep over it.
Nevertheless, I do, naturally, counsel you to back up the local copies of all your mail. In the event that a catastrophic outage at Google resulted in some or all of your messages disappearing from the server, you want to be sure you have another copy somewhere. So, you know the drill: read the book (or the other book), set up your backups, and test them regularly.
If you have more than one email account (and who doesn't these days?), you can use Gmail as a central repository - either forwarding your other accounts' mail to Gmail or letting Gmail check the messages in other accounts using POP. This lets all your accounts take advantage of Gmail's spam filtering and other features, and is especially helpful for devices like the iPhone that don't offer a consolidated inbox view for multiple accounts. What makes Gmail especially good as a central clearing house (as opposed to, say, MobileMe Mail) is that it offers a way to let you send outgoing mail from other addresses. I describe this entire process in detail in a Macworld article titled "Streamline E-mail with Gmail."
Last but not least, I'd like to put in a plug for the method of email organization I've found to be most effective and least stressful, which is to adopt a strategy that keeps one's inbox empty nearly all the time. As I type these words, there happen to be two messages in my inbox, and that's only because I'm not wired for multitasking and I haven't had a chance to deal with them yet. They'll be gone within the hour. If you want to read about (a simplified version of) how I pull this off despite receiving gazillions of messages every day, see my Macworld article "Empty Your Inbox."