Saturday, August 1, 2009

Emacs 23.1, Gnus and msmtp

After I upgraded my Emacs to the latest version on Windows, I found that my mail sending was not working anymore. And I use msmtp on cygwin to send emails instead of sendmail by subbing the sendmail binary with msmtp.

;;;;dont set this if you use msmtp!!!
;; (setq message-send-mail-function 'smtpmail-send-it)
(setq sendmail-program "/usr/sbin/msmtp")


This has been working for ages without any issues and I had not made any changes to my .gnus file. Baffling.

What's more, the *Messages* buffer kept saying 'Starting Firefox...'

So, I checked whether msmtp was sending emails through the command line. Check. works fine.

Inspected my .gnus file to see whether the paths were pointing to Emacs 22.2 version. Check. Nothing.

There I was, staring at the .gnus buffer wondering what to do next. Maybe debug this? I set
(setq gnus-verbose 9)
(setq gnus-verbose-backends 9)

and try sending again. Nothing in the *Messages* buffer.

I stare some more at .gnus buffer.
;;;;dont set this if you use msmtp!!!
;; (setq message-send-mail-function 'smtpmail-send-it)
;; (setq smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil)))

hmmm...dimly I sort of make out message sending is not working. Maybe I better check out the documentation and see what it says.
I hit C-h v on message-send-mail-function and I see

Valid values include `message-send-mail-with-sendmail'
`message-send-mail-with-mh', `message-send-mail-with-qmail',
`message-smtpmail-send-it', `smtpmail-send-it',
`feedmail-send-it' and `message-send-mail-with-mailclient'. The
default is system dependent and determined by the function
`message-send-mail-function'.
See also `send-mail-function'.


I get into the Emacs manual and search for 'send-mail-function'. And I find this

The variable `send-mail-function' controls how the default mail user
agent sends mail. It should be set to a function. In most cases, the
default is `sendmail-send-it', which delivers mail using the Sendmail
installation on the local host. On Mac OS X and MS-Windows, however,
the default is normally `mailclient-send-it', which passes the mail
buffer on to the system's designated mail client (see `mailclient.el').
To send mail through an SMTP server, set `send-mail-function' to
`smtpmail-send-it' and set up the Emacs SMTP library (*note Emacs SMTP
Library: (smtpmail)Top.).

So, that's why it was invoking Firefox! The OS was thinking Firefox was the associated default mail client and Emacs was simply calling that.

So message-send-mail-function was calling message-send-mail-with-mailclient instead of message-send-mail-with-sendmail.

I set
(setq message-send-mail-function 'message-send-mail-with-sendmail)

and now everything is back to normal. Now, if you noticed the Emacs manual talks only about send-mail-function and not message-send-mail-function. But since Gnus uses message.el, it was easy for me to find the correct switches.