November 26

sending and receiving gmail with Gnus and Fetchmail

I have been using Gnus as my email client for quite a while, over a year at least and despite its size and complexity (it was murder to first set up) I really like it now as it keeps me in Emacs and has all sorts of little gems for me to discover (like G-S u in the Group buffer).

One hitch has been getting gmail to work locally on my home computer. I figured out how to download gmail but not how to send replies through googles' smtp servers with the from address munged to use my gmail address. Today a kind soul helped me on the gnus newsgroup and everything works.

What I need installed: fetchmail emacs-snapshot msmtp

Then I need to configure gmail to do POP3, you can do this via `settings' -> `pop and forwarding'. Then fetchmail gets my ISP mail and my gmail and puts in my local mail spool which Gnus reads, and regular mail is sent via exim4 as usual but any gmail gets the From: header changed and sent out using msmtp. (I don't know why exim4 can't do this but whatever)
,----[ ~/.fetchmailrc ]
| poll pop.gmail.com with proto POP3 and options no dns
| user 'bzgirl@gmail.com' there with password 'XXXXXX' is 'orchid' here options ssl
| mda '/usr/bin/procmail -f fetchmail'
`----


,----[ crontab -e ] | */10 * * * * /usr/bin/fetchmail -s >> /home/orchid/.cronlog 2>&1 `----

,----[ ~/.msmtprc ] | account default | host smtp.gmail.com | auth on | user bzgirl@gmail.com | password XXXXXX | port 587 | tls on | logfile ~/.msmtplog `----

,----[ ~/.gnus.el ] | (setq gnus-posting-styles | '((".*" | (name "Angelina Carlton") | (address "debian@magma.ca") | (signature-file "/home/orchid/.signature")) | ("^nnml.*gmail" | (name "bzgirl") | (address "bzgirl@gmail.com") | (signature-file "/home/orchid/.signature.bzgirl")))) | ;; debug | ;(setq smtpmail-debug-info t) | ;(setq smtpmail-debug-verb t) | | (defun fs-change-smtp () | "Change the SMTP server according to the current from line." | (save-excursion | (let ((from | (save-restriction | (message-narrow-to-headers) | (message-fetch-field "from")))) | (message "From is `%s', setting `smtpmail-smtp-server' to `%s'" | from | (cond | ((string-match "bzgirl@gmail.com" from) | (setq sendmail-program "msmtp")) | (add-hook 'message-setup-hook 'fs-change-smtp)))))) `----
I am sure there are much better ways and one day hopefully Gnus will be able to handle gmail or any web mail natively, but until then I am quite happy this finally works.

Posted by æc♥ | Permanent Link