Updated 12th March 2016: For folks landing here via search engines and the like, I recommend ditching Gmail as a mail service altogether – as I now have. The hoops one has to jump through to simply get Gmail to behave normally with an external mail client are no longer worth the effort in light of the better business email hosting services now available. FastMail in particular is a cinch to set up, is stable and affordable, and just simply works with minimal setup on the Thunderbird side. Google clearly has zero interest or business reason to permit Gmail to work seamlessly with external clients, especially as it removes the vector for targeted advertising.
This is a brief guide describing how to quickly configure Apple Mail with Gmail over IMAP. This is pertaining to an old release of Mac OS, specifically OS 10.6.8, which is running Apple Mail 4.6. I am documenting this for the benefit of readers stuck on Mac OS 10.6 and who have been saddled with Apple Mail in lieu of a vastly superior, free, openly-developed mail client such as Thunderbird. Note that the procedure documented here may differ in later releases of Mac OS.
Note that IMAP must be first enabled in the Gmail account in question. Be sure to disable the labels you do not wish to access as folders in Apple Mail (especially the “All Mail” folder) as documented here.
The Gmail account can be created in Apple Mail using the add account wizard (or first-run setup procedure), which will attempt to obtain the correct server settings (incoming and outgoing servers, username) automatically. Note that if using an “@gmail.com” address the correct server settings will be retrieved correctly. However, if using a Google Apps Gmail account with a custom domain name (e.g. “@mycompany.co.nz”), the server and username settings will need to be configured manually (according to the Google documentation for IMAP client connections).
Once the account is added we need to perform some additional steps.
By default, Apple will use separate local folders (called “mailboxes” in Apple Mail-speak for some bizarre reason) for the account Sent and Trash folders. We need to map the Gmail “Sent Mail” and “Bin” IMAP folders to these local folders, so that when email is sent or deleted in Apple Mail it will be updated in the server-side Gmail “Sent Mail” and “Bin” folders, respectively.
To do this, first select the relevant Gmail folder, and then go to “Mailbox -> Use This Mailbox For”. In this example we are mapping the Gmail “Sent Mail” folder to be used for Apple Mail sent items. The “Sent” folder visible at the top-left of the folder listing in Apple Mail will then contain and be sycnchronised with our Gmail “Sent Mail” folder:
Perform the same for mapping the Apple Mail “Trash” folder to the Gmail “Bin” folder. Once done, test that sent mail and deleted items are synchronised both ways between Apple Mail and Gmail (use the Gmail web interface to verify this). If these steps are missed or misconfigured, you will end up with local mail stores in Apple Mail for sent and deleted items (this is totally undesirable for reasons of backup, amongst other things).
Note that counter to the official Google documentation (and what we would configure in Thunderbird for example), with the above folder mapping configuration in place we have to configure Apple Mail to store sent items on the server. Mail sent out through Google’s SMTP servers is normally copied into the “Sent Items” folder anyway regardless of the client settings, but in Apple Mail this has to be enabled explicitly (as disabling it also disables the folder mapping performed above):
Finally, in Apple Mail we disable the built-in Junk email filter (as spam filtering is performed automatically in Gmail):
Apple Mail should now be configured successfully for basic interoperability with Gmail.