GnusGmail

From TerjeRosten

Contents

Howto: Send and receive mail for a Gmail account in Gnus

Background

It's possible to read and send mail for a Gmail account without using the web interface. You can download messages with POP, however SSL is required. The port used is 995, not 110. The server is pop.gmail.com. To send mail, SMTP with authentication is used, username and password is required. The network stream must to be encrypted with StartTLS. Port is 465 og 587, SMTP server is smtp.gmail.com.

With some help from bleeding-edge software Gnus can be set up to meet these requirements.

Software

Software needed to get things to work:

  • Emacs from CVS
  • Gnus from CVS
  • Gnutls package { In Fedora Core the required gnutls-cli binary is included in the gnutls-devel rpm package. }

But even this is not enough, pop.el in Gnus do not support SSL which is required. Replace pop.el in Gnus with the one in CVS from m17n.org: pop.el with SSL support.

If you don't want to build Emacs and Gnus from CVS you can try to upgrade these important files:

  • Emacs: lisp/mail/smtpmail.el
  • Gnus: lisp/starttls.el

and of course pop3.el in Gnus.

Config

First you have to enable pop for you Gmail account, login and choose Settings in the upper right corner, then choose Forwarding and POP: Enable POP and Save Changes.

Then add something like this to ~/.gnus:

{ In this example all mail to the Gmail account is assumed to be sent to a gmail nnml group. When you reply to mail in the group your Gmail address is used and the mail is sent by the Gmail smtp server. }


   ;; The following line is needed when using pop3.el from T-gnus (m17n.org).
   (eval-after-load "mail-source" '(require 'pop3))


   (setq gnus-posting-styles
      '((".*"
	 (name "Joe User")
	 (address "joeuser@example.org"))
        ("^nnml.*gmail"
	 (address "joeuser@gmail.com"))))


   (setq mail-sources					
      '((file :path "/var/spool/mail/joeuser")
        (pop :server "pop.gmail.com"
	     :port 995
	     :user "joeuser"
	     :connection ssl
	     :leave 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 "joeuser@gmail.com" from)
		 ;; Use stmp-auth
		 (message "Using smtp-auth")
		 ;; Sending mail
		 (setq message-send-mail-function 'smtpmail-send-it)
		 (setq smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil)))
		 (setq smtpmail-auth-credentials '(("smtp.gmail.com" 587 "joeuser" nil)))
		 (setq smtpmail-default-smtp-server "smtp.gmail.com")
		 (setq smtpmail-smtp-server "smtp.gmail.com")
		 (setq smtpmail-smtp-service 587))
		((string-match "joeuser@example.org" from)
		 ;; Use local sendmail
		 (message "Using local sendmail")
		 (setq message-send-mail-function `message-send-mail-with-sendmail))
		(t
		 (error 
		  (concat "Don't know which mail server to use for "
			  from))))))))

    (add-hook 'message-setup-hook 'fs-change-smtp)