NOTE: For Mavericks, the way Mail.app works with Gmail completely changed. The most important change is that Delete will move the message to Trash and Archive will move the message to All Mail (like a normal Gmail Archive command). It is important to have All Mail visible to IMAP in the Gmail settings.
This is very annoying, and you may be better off using a new mail client like Airmail.
Here are my settings for using Mail.app with Gmail and Google Apps. It took a lot of fussing to get these right, so I'm putting them here to point people to if they are having problem.
My main goals were:
These are the Gmail settings:
In particular, it's important to set the Auto-Expune on so that deletes from Apple are sent directly to Gmail. Otherwise you will log in to the web app and still see mail in the Inbox that you archived on Mail.app.
Here are the mailbox settings that I use:
Todd Nemet >