So I have been using gmail more and more lately because one of my friend’s work blocks my normal outgoing mail server. I really dislike webmail interfaces though and usually use mutt(1) as my MUA.
I can use the Gmail’s imap service to read mail, but sending mail is the whole reason I am not using my normal @ub3rgeek.net mail address and it would be nice for the SPF records to match up.
By default mutt(1) uses sendmail(8) to ship your message off to the local MTA, which then takes care of delivering your message. Now I don’t want to smarthost ALL my mail through Gmail’s servers otherwise that would be the easy way out, so the quick and dirty method was to whip up a quick little python program that would act as a SMTP client in place of sendmail(8).
Bits:
- Mutt Config (muttrc and imap are the important ones)
- smtpc.py
# gmail
account-hook imaps://imap.gmail.com/ 'set imap_user=""'
account-hook imaps://imap.gmail.com/ 'set imap_pass=""'
account-hook imaps://imap.gmail.com/ 'set sendmail="/home/mernisse/bin/smtpc.py -s -h smtp.gmail.com -u you@gmail.com -p your_password -f you@gmail.com"'
folder-hook imaps://imap.gmail.com/ 'set from="mernisse@gmail.com"'
folder-hook imaps://imap.gmail.com/ 'set record="imaps://imap.gmail.com/[Gmail]/Sent Mail"'
This is the important part (it is in the imap file in my config), this overrides the other account settings and sets my Gmail username and password for the imaps driver and sets the sendmail binary to my smtpc.py script, passing the arguments for ssl, host smtp.gmail.com, my username and password, as well as the From address. Mutt puts the To: addresses on the command line after all options, since that is what sendmail(8) expects.
You could of course use this to relay to just about any mail server if you like. I continue to set the correct envelope sender, as well as the Sent folder so that the Gmail web interface gets copies of all the replies I send which it happily stuffs into the conversation view.
[...] BlackBerry I use mutt as a mail user agent. I have a few scripts already written to hook mutt into GMail’s outgoing mail server and Google Calendar so I figured if I was going to use my GMail contacts on the BlackBerry I should [...]
I wrote a similar script for use with mutt which automatically tries to use a secure connection first, including ssl:
http://www.ynform.org/w/Pub/SendmailPy