How to make Gmail IMAP play nice with Apple Mail.app

I know. This should be a no-brainer. However, I didn't use Mail.app with Gmail for a long time because Mail.app created strange labels in my Gmail Web interface and, most deal breakingly, refused to delete my messages but instead kicked them into a new label or back into the Archive label (depending on the option I checked in the Accounts --> Mailbox Behaviors --> Trash section). This meant that I had deleted messages scattered all over Gmail and a bunch of weird labels that I didn't want. (Please, no comments on "why would you delete anything from Gmail, with those gazillion gigs of storage?"...I really don't want stored copies of notifications that my credit card bill is available! I can stagger on without it!) Invariably someone is wondering, "WTF is IMAP?" There is a complete technical explanation about POP and IMAP here. Basically, you've got your Web mail, which is what you see when you get your mail through your Web browser; your POP mail, which downloads a copy of your mail from the server to your local computer (through Eudora, Thunderbird, Mail.app, or another mail client; the fate of the original e-mail is to remain undisturbed on the server or to be deleted); or your IMAP mail, which syncs your e-mail between the server and your local computer. Why care? Because if you, like me, have various labels or folders with which you organize your mail, it's a pain in the ya-ha to keep them spic and span on your local computer and then just have a messy inbox in your Web mail. I want it the same no matter how I approach my e-mail, and Google is nice enough to provide free IMAP. IMAP is not for folks who don't have always-on Internet connections. No connection = no mail.

Now I will make another brief digression because undoubtedly readers will wonder why I would not want to solely use Gmail's fabulous minimalistic Web interface. It's OK. It's way better than Yahoo! Mail. I use it without flinching too much if it's convenient. Still, I like Mail.app because there are no ads, because it's easy to include photos, and because I like the data handlers. I use Mail Act-On to assign keystrokes that deal with my mail more intuitively than Gmail's. I additionally like the integration with Apple's Address Book and the fact that custom pics for people show up in their e-mails (hey! eye candy is A-OK!). I can also now report that dotmac does effectively sync all the settings and accounts for Mail.app. Cool.

So. If this all sounds good, head over to Gmail and read their instructions for setting up IMAP with Apple Mail, except when you select Gmail in the accounts pane and then go to Mailbox Behaviors --> Trash, tick both options ("Move Deleted Messages to the Trash Mailbox" and "Store Deleted Messages on Server"). This is important as it directly counters Google's directions. Finally, close out of the preferences, saving everything, and head up to the MAILBOXES section in the top left of your Mail.app window. Click the arrow next to "Sent" and then when it expands click once on "Gmail." Head way up to your menubar and click Mailbox --> Use This Mailbox For --> Sent. Do the same thing for "Trash" (only pick Trash instead of Sent, obviously). You can use this same sequence to use your Gmail Spam folder for Apple.app junk if you have selected "Move it to the Junk Mailbox" in the Junk Mail preference pane.

Voila! You do not have sent and deleted mail all over the place: only in the "Sent Mail" and "Trash" labels in Gmail. Good times for everyone.