GnusGmail

Quickstart

Now put the following in your ~/.gnus file, replacing <EMAIL_ADDRESS> and <FULL NAME> by your, uhm, email address and full name:

(setq user-mail-address "<EMAIL_ADDRESS>"
      user-full-name "<FULL NAME>")

(setq gnus-select-method
      '(nnimap "gmail"
	       (nnimap-address "imap.gmail.com")  ; it could also be imap.googlemail.com if that's your server.
	       (nnimap-server-port "imaps")
	       (nnimap-stream ssl)))

(setq smtpmail-smtp-server "smtp.gmail.com"
      smtpmail-smtp-service 587
      gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")

Put the following in your ~/.authinfo file or better yet, in ~/.authinfo.gpg which will be automatically encrypted with GnuPG (see GnusAuthinfo and GnusEncryptedAuthInfo, as well as the ‘auth’ info node in emacs using C-h i d m auth RET), replacing <USER> with your email address and replacing <APP-PASSWORD> with your application-specific password

machine imap.gmail.com login <USER> password <APP-PASSWORD> port imaps
machine smtp.gmail.com login <USER> password <APP-PASSWORD> port 587

NOTE: As of now, it is required that you enable 2 step authentication and then create an application specific password this is a 16 digit code that will allow gnus to connect to your account:

When sending your first email from gnus, you might get a STARTTLS error. If you’re using homebrew in Mac OS X, you can install the necessary package with brew install gnutls.

You can find more information in the following sections.

Run ‘M-x gnus’ and enjoy.

Introduction

Gnus can connect to the Gmail server in two ways: by POP3, or by IMAP. Each protocol behaves in a different way, so you can select the one which better suits your needs. Furthermore, as a third solution you can download your mail with an external program like fetchmail and let Gnus handle it locally.

This page describes how to configure Gnus to read and send mails from your gmail account, and should also explain how to do in Gnus what you can do through the web interface.


Configuration

Accessing Gmail via IMAP

Firstly, don’t forget to enable IMAP in your Gmail account (settings->forwarding POP/IMAP). Then configure ~/.gnus and ~/.authinfo[.gpg] as shown above.

Alternatively, you can configure Gmail IMAP as a secondary select method for Gnus:

(add-to-list 'gnus-secondary-select-methods '(nnimap "gmail"
                                  (nnimap-address "imap.gmail.com")  ; it could also be imap.googlemail.com if that's your server.
                                  (nnimap-server-port "imaps")
                                  (nnimap-stream ssl)
                                  (nnmail-expiry-target "nnimap+gmail:[Gmail]/Trash")  ; Move expired messages to Gmail's trash.
                                  (nnmail-expiry-wait immediate))) ; Mails marked as expired can be processed immediately.

(setq smtpmail-smtp-server "smtp.gmail.com"
      smtpmail-smtp-service 587
      gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")

Alternatively, if your email is not @gmail.com, you can use smtp.googlemail.com, imap.googlemail.com, and use 465 instead of 587.

Accessing the [Gmail] folders

All Gmail system labels have a prefix [Gmail], which matches the default value of gnus-ignored-newsgroups. A workaround is to redefine it as follows:

    ;; Make Gnus NOT ignore [Gmail] mailboxes
    (setq gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")

Adaptive Scoring in the [Gmail] folders

There is a bug in Gnus v5.13 that prevent adaptive scoring to be used in [Gmail] folders. The ADAPT files are created and updated, but scores are not adjusted.

If you want to use adaptive scores in these folders, a simple work-around is to define nnheader-file-name-translation-alist as follows:

    ;; Replace [ and ] with _ in ADAPT file names
    (setq nnheader-file-name-translation-alist '((?[ . ?_) (?] . ?_)) )

Note that this will not rename ADAPT files in your News directory. You need to either rename existing files or delete them.

Accessing Gmail via POP

Note(This needs an update to account for the fact that you now need 2 step authentication)

“Retrieving mail with POP3 is supported over SSL/TLS and with StartTLS.” (from GNUS-NEWS)

Put the following in your gnus-init-file is sufficient.

(setq mail-sources
      '((pop :server "pop.gmail.com"
             :port 995
             :user "Leo@gmail.com"
             :password "wrongpw"
             :stream ssl)))

I have tested this with No Gnus 0.6 (2006-10-19) and XftGnuEmacs (2006-10-04).

In case you want to use gnus only as a pop-mail reader, you need to add the following line before adding mail sources:

(setq gnus-select-method '(nnml ""))

According to http://mail.google.com/support/bin/answer.py?answer=13287 the user name must include @gmail.com – AdrianAichner


There is bleeding edge support for sending/getting email through Gmail using only Gnus (and not the webmail interface.) I’ve verified that this works (rather well in fact.)

  1. Configure your Gmail account for POP support. This is under Settings in the gmail web interface.
  2. Use CVS Emacs and CVS Gnus. It won’t work any other way.
  3. Replace your installation’s “pop3.el” and “pop3.elc” with those linked to from this page: http://www.pvv.ntnu.no/~terjeros/wiki/GnusGmail
  4. Configure as on the linked page.

– NOTE: you also need ssl.el, which doesn’t seem to come with the current GNU CVS. I found it with a quick google search.

– I still can seem to get any messages from the server. I’ve solved the problems with connection and missing load files, but now it will connect and not report any of the messages. Any hints?

Accessing Gmail via an external mail retriever

Note that you can also get your mail from Gmail using fetchmail if that’s installed on your home system. The following .fetchmailrc works for me:

 poll pop.gmail.com with proto POP3 and options no dns
 user 'USERNAME@gmail.com' there with password 'PASSWORD' is 'LOCALUSERNAME' here options ssl

You can then set up a cron job to run fetchmail every few minutes:

 */3 * * * * fetchmail -s >/dev/null 2>&1

– ALTERNATE: Instead of using cron, you could always add “set daemon 300” (without the quotes) to your .fetchmailrc to use its built-in daemonic capabilities. The “300” tells it to run every 300 seconds (five minutes). Change this number to suit your tastes.

and let gnus read your mail from wherever the usual location is on your system.

Another possibility: if you set up a Gmail filter by entering “in:inbox” in the “Has the words” field (you will get an error message but ignore it) you can have Gmail forward all your mail from your inbox (leaving spam behind) to some location where you can access it without changing your emacs or gnus installation.

Not even the above is necessary (as of 2006-12-02), gmail has now an option for forwarding the whole inbox to another address. dida

How to use offlineimap and the dovecot mail server

From http://sachachua.com/blog/2008/05/geek-how-to-use-offlineimap-and-the-dovecot-mail-server-to-read-your-gmail-in-emacs-efficiently/

Make sure you’ve set up Postfix or some other mail server that can send mail. I’m not going to cover that because my configuration for outgoing mail doesn’t use Gmail.

Install dovecot (IMAP server) and offlineimap (IMAP synchronization). You can probably find binaries for your distribution.

Edit /etc/dovecot.conf and set the following:

    default_mail_env = maildir:%h/Maildir

Put the following in ~/.offlineimaprc, changing your_local_username, your_username, and your_gmail_password:

    [general]
    accounts = Gmail
    maxsyncaccounts = 1
    [Account Gmail]
    localrepository = Local
    remoterepository = Remote
    [Repository Local]
    type = IMAP
    remotehost = localhost
    port = 143
    remoteuser = your_local_username
    [Repository Remote]
    type = IMAP
    remotehost = imap.gmail.com
    remoteuser = your_username@gmail.com
    remotepass = your_gmail_password
    ssl = yes
    maxconnections = 1
    realdelete = no
    folderfilter = lambda foldername: foldername in ['INBOX']

If you feel comfortable specifying your password for your local account in your ~/.offlineimaprc, you can do so by adding a remotepass line under the remoteuser line in the [Repository Local] section.

chmod go-rwx ~/.offlineimaprc for a little bit of safety.

Type offlineimap to start synchronizing.

While that’s synchronizing, use something like this as your ~/.gnus:

    (setq gnus-select-method
          '(nnimap "Mail"
               (nnimap-address "localhost")
               (nnimap-stream network)
               (nnimap-authenticator login)))
    (setq user-mail-address "youremail@example.com")
    (setq gnus-ignored-from-addresses "youruser")

Start Emacs. Start Gnus with M-x gnus. If you don’t see the INBOX group, press ^ (gnus-group-enter-server-mode), open nnimap:Mail, move your cursor to the INBOX, and either press RET to go into the group or press u (gnus-browse-unsubscribe-current-group) to toggle the subscription status until you’re subscribed to the group. Then it should show up on the group screen (M-x gnus).

Sending mail through Gmail's SMTP server

See the section with the IMAP configuration for the required settings to configure SMTP.

Storing sent mail in the server

Mails will automatically be stored in the proper “[Gmail]/Sent Mail” folder if you configured Gnus to send mail using Gmail’s SMTP server as detailed in the IMAP configuration section.

Usage

Archiving mails

What is the equivalent Gnus command to the “Archive” button? (Remove from “Inbox” and stay in “All mail”)

Remove the “Inbox” tag by deleting from the “INBOX” folder with B DEL.

Deleting mails

How can you delete a mail in Gnus so that it disappears from your Inbox in Gmail and goes to Trash?

B m does gnus-summary-move-article. Invoke it, then type “[Gmail]/Trash”. In Gmail terms, this will remove the “Inbox” label and apply the “Trash” label. Messages in the trash don’t show up in other folders, even though they may have other labels. The Gmail server automatically purges the emails which have been in the “Trash” folder for more than 30 days.

If you do not want to wait for the 30 days and want to immediately delete a message, it must first be moved to the Trash folder (or be in the Spam folder). Then, after opening the Trash or Spam folder, you can delete the message using B DEL (gnus-summary-delete-article). Using the gnus-summary-delete-article function from any other folder than Trash or Spam will strip the message of that label rather than deleting the message permanently.

See the next section (Expiring mails) for a more powerful way to delete emails.

Expiring mails

The Gnus way to delete mails would be to expire them. By default, a mail marked as expired gets hidden from the view (it is considered read) for 7 days before being deleted. With the way the delete action is implemented in Gmail, this means that after 7 days, the expired messages are archived and kept forever. If, like me, the idea of leaving all your trash accumulating in your backyard doesn’t sound too appealing, the following options can be useful:

  1. nnmail-expiry-target: To tell the expiry process where to move the expired messages to. I set this to Gmail’s trash, such as: (setq nnmail-expiry-target "nnimap+gmail:[Gmail]/Trash").
  2. nnmail-expiry-wait: This can be used to configure how long you’d like the expired messages to stick around. Since Gmail is already keeping the messages moved to its trash folder for 30 days, I set this to immediate: (setq nnmail-expiry-wait 'immediate)

If you copied your basic configuration from the Configuration section, it should already be configured that way for you.

Catching up

If you are seeing some mails in Gnus, and then you delete them in Gmail’s web interface, how can make them also disappear from the Gnus view?

g does gnus-group-get-new-news in group mode. This doesn’t seem to work completely correctly: it may report incorrect numbers of unread messages in each group after an update.

Only g (or M-g) didn’t work with the normal configuration. I have seen that Gmail starts working perfectly in Gnus after you disable Gnus Agent, with (setq gnus-agent nil). It seems that gnus-agent and nnimap don’t play well together.

A less drastic solution is to only disable gnus-agent for Gmail. Go to the server buffer with ^ and disable the agent for Gmail with J r.

Conversations view

How can you see in a single thread both the received message and the sent messages to a person? (As in Gmail’s web interface).

Create a nnvirtual group that contains both “nnimap+imap.gmail.com:INBOX” and “nnimap+imap.gmail.com:[Gmail]/Sent Mail”, and you can have conversational view in that group.

Then click “u” on INBOX to avoid seeing both nnvirtual:INBOX+sent and INBOX (note: don’t use “k”, then you’ll lose the read/unread/star flags; see https://www.gnu.org/software/emacs/manual/html_node/gnus/Group-Levels.html#Group-Levels).

*Article* extracts/previews in *Summary*

Is it possible to show the first non-reply line of the article within ‘gnus-summary-line-format’, in order to get a “preview”?

Tags

How can you assign and remove tags from messages?

B c and B DEL, respectively.

Empty spam folder

How can you access your spam folder and review and really delete all messages? (Not move them to Trash!)

B DEL

How can you see the spam folder in the first place? Since I don’t see it in the „Gnus browse server“ buffer (accesible from key ^). It’s the only folder missing.

See the configuration section.

Drafts

How can you stop composition of an e-mail and store it in Gmail’s draft folder? How can you recover it again?

In the same way as you can for any other gnus backend (composition is separate from the sending method, mostly): save the mail via C-x C-s and then exit it with C-c C-k. When you look in your nndraft:drafts folder, you’ll see it there. To edit, hit e on the mail.

nndraft is fast, but sometimes it may be convenient to store the draft in the remote folder (for mobility between computers). Any simple solution for that?

E-mail search

How can you search a text string through all your e-mails?

This works only for IMAP.

From Searching IMAP in Gnus. Add the following line to your .emacs:

(require 'nnir)

Then add the following line to the secondary-method in .gnus.el

(nnir-search-engine imap)

It should look like this:

(add-to-list 'gnus-secondary-select-methods '(nnimap "gmail"
				 (nnimap-stream ssl)
 				 (nnimap-address "imap.gmail.com")
 				 (nnimap-server-port 993)
 				 (nnir-search-engine imap)))

Restart Gnus. With G G in the Groups buffer, you search for mails in the current group. Note that this will not work in virtual groups. If you want to search on all your mails, you should add the folder ‘All Mail’.

Add the following to .gnus.el to enable the same search syntax that Gmail supports:

(add-to-list 'nnir-imap-search-arguments '("gmail" . "X-GM-RAW"))
(setq nnir-imap-default-search-key "gmail")

This is especially useful for restricting search to particular dates (e.g. “before:2016/11/1”, “after:2016/11/5”), finding attachments (e.g. “has:attachment”, “filename:pdf”), matching messages without a term (e.g. “-foo”), or with a particular state (e.g. “is:starred”, “is:important”, “is:unread”).

Contact autocompletion

When you compose a message in Gmail, you type the first letters, and a list open ups with the contacts whose name matches what you wrote. How can you manage your contacts and do autocompletion in Gnus?

Using BBDB (see CategoryBbdb) you can manage your contacts, and have their names autocompleted when composing new messages.

But Gmail tracks information automatically about all e-mails ever seen, whereas in BBDB you must add each manually. Which BbdbConfiguration must be applied to act more Big-Brother-alike, like Gmail?

You can put the following in your .gnus or init.el or whatever:

(setq bbdb/news-auto-create-p t)

There is also a new project called Org-contacts which combines Org-mode (for email storage) and Gnus (for mailing). It works quite well!

Reply-to with the same address as it was sent to

You can emulate this Gmail feature with the variable ‘gnus-posting-styles’, which also allows you to set a whole bunch of other variables based on the email you reply to or the group you’re in. A very simple example, for just two addresses, would be:

    (setq gnus-posting-styles
      '(((header "to" "myname@gmail.com")
         (address "myname@gmail.com"))
	((header "to" "blah@blah.com")
         (address "blah@blah.com"))
	((header "cc" "myname@gmail.com")
         (address "myname@gmail.com"))
	((header "cc" "blah@blah.com")
         (address "blah@blah.com"))))

See the info node on that variable, you could easily automatically add this from a list.

Chat

Gmail used to provide an interface to their chat service using XMPP, but such support was dropped somewhere around 2013.

How do actions sync in IMAP?

From Gmail Help

Action on clientResult in Gmail on the webCommand in Gnus
Open a message Mark a message as read RET
Flag a message Apply a star to the message !
Unflag a message Remove the star from the message M-u
Move a message to a folder Apply a label to the message B m
Move a message to a folder within a folder Apply a label showing folder hierarchy (’MainFolder/SubFolder’)B m
Create a folder Create a label B m to nonexistent folder will create it.
Move a message to [Gmail]/Spam Report a message as spam B m [Gmail]/Spam RET
Move a message to [Gmail]/Trash Move a message to Trash B m [Gmail]/Trash RET
Send a message Store message in Sent Mail m
Delete a message in inbox Remove the message from inbox B DEL
Delete a message from a folder Remove that label from the message B DEL
Delete a message from [Gmail]/Spam or [Gmail]/Trash Delete the message permanently B DEL

CategoryGnus