Like many folks, I use Google for more and more. When I noticed Google's announcement that Gmail supports IMAP, I knew I could read my Gmail from Emacs.
The question was, how do you set up the integration? The Emacs wiki had instructions on how to read email, which worked nicely. But I wanted to enable Gmail to gather the mail I sent from Emacs into its conversation groups (it's no Gnus threading, but it's a start). So how to enable that? At first I automatically Bcc'ed my Gmail account, but that was hacky. Then I noticed Gmail lets you use their SMTP server.
I found some documentation on how to use it, but it didn't work for me (wrong ports evidentially), and it was integrated differently than what I wanted.
So I used my favorite Emacs lisp feature, advice, and wrote the following snippet. It checks to see if the 'From:' address is a gmail address, in which case it uses Gmail's SMTP server.
(defadvice message-send-mail (around gmail-message-send-mail protect activate)
"Set up SMTP settings to use Gmail's server when mail is from a gmail.com address."
(string-match "gmail.com" (message-fetch-field "from")))
(let ((message-send-mail-function 'smtpmail-send-it)
;; gmail says use port 465 or 587, but 25 works and those don't, go figure
(smtpmail-starttls-credentials '(("smtp.gmail.com" 25 nil nil)))
(smtpmail-auth-credentials '(("smtp.gmail.com" 25 "firstname.lastname@example.org" nil)))
Note: You can also download the snippet directly.
And, as a good netizen, I updated the wiki appropriately.