Sunday, July 12, 2009

Configuring Gnus and Gmail With IMAP on MS Windows

So I don't forget, here is the long awaited configuration. If anyone is wondering why Emacs and Gnus are not more widely used, they could consider that configuring the two to interface with one of the most widely used free e-mail services is a mighty chore.

Anyway, to use IMAP, the following steps are required:

  1. Download an ssl client. The one that worked for me was (curiously) from GIT on windows.

  2. Configure gmail to allow IMAP.

  3. Enter the following magic in your .gnus.el file (obviously changing what's needed):
    (setq imap-ssl-program-binary
    "c:/progra~1/git/bin/openssl.exe")

    (setq imap-ssl-program-arguments
    "s_client -quiet -ssl3 -connect %s:%p")

    (setq imap-ssl-program
    (concat imap-ssl-program-binary

    " "
    imap-ssl-program-arguments))



    (setq gnus-secondary-select-methods
    '((nnimap "gmail"
    (nnimap-address "imap.gmail.com")
    (nnimap-server-port 993)
    (nnimap-stream ssl)
    (nnimap-authinfo-file
    "~/.authinfo"))))


The first part sets up SSL. Note the program arguments that I absolutely needed to get IMAP to work. The second part of the code snippet is the actual configuration of IMAP; it's pretty much the standard out of the Gnus manual.

The next step is configuring SMTP to send. This was by far the more difficult task of the two. Here are some steps to make this work:
  1. Download Gnutls. I had to get the one that came with Cygwin.

  2. Patch starttls.el in the following manner:

    • Add the following definition:
      (defcustom starttls-kill-program
      "c:\\cygwin\\bin\\kill"
      "External kill command to send
      SIGALRM to starttls."
      :group 'starttls)
    • This definition redefines the kill command. The default from Linux/Unix does not work on Windows.

    • Replace any appearance of
      (signal-process (process-id process)
      'SIGALRM)

      with

      (call-process starttls-kill-program
      nil nil nil "-ALRM"
      (format "%d" (process-id process)))
    • Byte compile the new file to starttls.elc

    I found this fix here.

  3. Add the following to your .emacs :

    (setq message-send-mail-function
    'smtpmail-send-it)

    (setq starttls-use-gnutls t)
    (setq starttls-gnutls-program
    "c:/cygwin/bin/gnutls-cli.exe")

    (setq smtpmail-starttls-credentials
    '(("smtp.gmail.com" 587 nil nil)))
    (setq smtpmail-auth-credentials
    (expand-file-name "~/.authinfo"))
    (setq smtpmail-default-smtp-server
    "smtp.gmail.com")

    (setq smtpmail-smtp-server
    "smtp.gmail.com")

    (setq smtpmail-smtp-service 587)
    (load-library "smtpmail")
    (setq send-mail-function 'smtpmail-send-it)
    (setq smtpmail-debug-info t)
  4. Finally, create a .authinfo file, which has at least the following lines in it (edit userid and password to reflect yours. If you leave off password, you will be prompted.):

    machine imap.gmail.com login userid@gmail.com
    password xxxx port 993

    maching smtp.gmail.com login userid@gmail.com
    password xx
    xx


For reference, I am using the latest CVS version of Emacs 23 (from 7/11/2009), and Gnus 5.13 that came along with Emacs. I hope this helps somebody.

Labels: , ,

0 Comments:

Post a Comment

<< Home