Thursday, February 19, 2009

Mutt, Emacs, Postfix and Gmail

Update 20/02/2009: this article at The Lumber Loom is what this was supposed to be. You don't even need postfix, it seems. The 'Composing mail' part is still worth a look.

This is the current setup I use. Procmail could also be added in, but Gmail IMAP and filters are enough for me at the moment. The following setup assumes that you're using a single mail account, and are generally a simple user - not an e-mail provider or something.

Receiving mail

If you want to use IMAP to access your e-mail instead of fetching it and reading from your own computer, mutt is quite simple to configure. Here's the relevant part of my .muttrc:

set imap_login = 'abesto0'
set folder="imaps://abesto0@imap.gmail.com/INBOX"
set record="=Sent"
set postponed="=Drafts"
set ssl_starttls=yes
set ssl_force_tls=yes
set imap_passive = no
set mail_check=60
set timeout=10
set header_cache=~/.hcache
set imap_user = 'abesto0@gmail.com'

Composing mail

Mutt uses an external editor for writing mail. Using Emacs for that is simple enough. Add this to your .muttrc:
set editor = 'emacsclient %s'
And this to your .emacs, if you want to edit in mail-mode:
(add-to-list 'auto-mode-alist '("mutt-HOSTNAME" . mail-mode))
Aaaand that's it.

Sending mail

This one's a bit more complicated. Mutt itself won't send mails. It will, however, happily use another application to do it for you. This program is sendmail by default, but postfix provides a sendmail compatibility interface, so it's a drop-in replacement.

After searching the 'net all afternoon, a comment on a blog solved my problems with routing mail through the Gmail SMTP server. I've lost that blog some time in the last four hours - sorry. Most other tutorials make you create certificates, but it's apparently not necessary. Adding the following to /etc/postfix/main.cf seems to be enough:

relayhost= [smtp.gmail.com]:587

smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

You'll have to tell postfix what username and password to use. This is done by writing /etc/postfix/sasl_passwd with the following format:

[smtp.gmail.com]:587    user.name@gmail.com:password

Then, in /etc/postfix run the following command, to create a hash db: postmap sasl_passwd
This creates sasl_passwd.db, containing what you just entered in a hash database. You can delete sasl_passwd now, if you want (not sasl_passwd.db).

You can reload the postfix configuration without restarting the daemon with postfix reload. After that, you should be ready to use your mutt-emacs-postfix-gmail setup. Have fun :)

No comments:

Post a Comment