Starter Kit Gnus – IMAP

Based on the instructions at emacswiki:GnusGmail.

to use this file:

  1. personal information in this file (specifically in the code blocks which will be tangled in the next step) globally replace "your-name" with your gmail username, and "your-password" with your gmail password.
  2. tangle this file Run the org-babel-tangle command to extract the code embedded in this file into a starter-git-gnus-imap.el file which can be added to your configuration, and a ~/.authinfo file which will be used by gnus.
  3. load this configuration If you have a recent version of Org-mode (i.e. after 7.0) or are using the literate Emacs Starter Kit, then this file can be loaded directly using the org-babel-load-file function, or by placing it in your load path (if you're using the starter kit).

    Alternately ensure that the gnus-gmail.el file generated by the previous step is loaded by your configuration.

  4. fire up gnus This can be done with the command M-x gnus
  5. view your mail After gnus boots up you will see the "Group Buffer" (see Group-Buffer). Each line is a mail "Group", hit SPACE or ENTER on a group to view it's contents. You should see an "INBOX" group which contains the mail in your gmail account. If not, you can jump to the "INBOX" group by
    • pressing j for "jump"
    • tab completing the name "INBOX"
    • pressing U for "unkill" meaning this will now always be displayed in your Group buffer when you have new mail
  6. customize Gnus has unrivalled capacity for customization. Once your comfortable with basic usage, take some time to browse through the very readable Gnus Manual to learn untold tricks (see also Starter-kit-gnus:Customizations).

saving mail locally

Where your mail will be saved locally default value will be ~/gmail.

(require 'gnus)
(setq nnml-directory "~/gmail")
(setq message-directory "~/gmail")

All Gmail groups will be ignored by the default value of gnus-ignored-newsgroups, so let's change that default value.

(setq gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\”]\”[#’()]")

getting mail

Set Gmail as the primary source for incoming mail (Gnus can aggregate many email and/or newsgroup sources).

(setq gnus-select-method
      '(nnimap "gmail"
               (nnimap-address "imap.gmail.com")
               (nnimap-server-port 993)
               (nnimap-stream ssl)))

Place a line like the following in ~/.authinfo

machine imap.gmail.com login your-name@gmail.com password your-password port 993

and make sure that no-one else can read it with

chmod 600 ~/.authinfo

sending mail

Requirement: gnus uses the gnutls tool for encrypted sending of email to the Gmail SMTP server. This is easily installed on modern Debian (including Ubuntu) systems with

apt-get install gnutls-bin

The following configures gnus to use the Gmail SMTP server for sending email.

(setq message-send-mail-function 'smtpmail-send-it
      smtpmail-starttls-credentials '(("smtp.gmail.com" 587 nil nil))
      smtpmail-auth-credentials '(("smtp.gmail.com" 587 "your-name@gmail.com" nil))
      smtpmail-default-smtp-server "smtp.gmail.com"
      smtpmail-smtp-server "smtp.gmail.com"
      smtpmail-smtp-service 587
      starttls-use-gnutls t)

If you don't want to be prompted for a password on every mail sent, you can add the following line to your ~/.authinfo.

machine smtp.gmail.com login your-name@gmail.com your-password secret port 587