Last edit


< To send messages, you will need to have ##starttls## installed. If you're using homebrew in Mac OS X, you can install it with ##brew install gnutls##.


> 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##.


Put the following in your ~/.gnus file and replace “” with your email address:

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

(setq message-send-mail-function 'smtpmail-send-it
      smtpmail-starttls-credentials '(("" 587 nil nil))
      smtpmail-auth-credentials '(("" 587
				   "" nil))
      smtpmail-default-smtp-server ""
      smtpmail-smtp-server ""
      smtpmail-smtp-service 587
      gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")

Put the following in your ~/.authinfo file and replace “” with your email addres and replace “secret” with your password—or your application-specific password:

machine login password secret port 993
machine login password secret port 587

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.


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’re able to do through the web interface.


Accessing Gmail via Imap

Firstly, don’t forget to enable IMAP in your Gmail account (settings->forwarding POP/IMAP). Settings to tell gnus to use Gmail’s IMAP as a (secondary) select method are as follows:

(add-to-list 'gnus-secondary-select-methods '(nnimap "gmail"
                                  (nnimap-address "")  ; it could also be if that's your server.
                                  (nnimap-server-port 993)
                                  (nnimap-stream ssl)))

with a line like the following one in your ~/.authinfo

machine login password secret port 993

If you prefer enable Gmail as primary select method (if you choose this, there is no need to put the previous section in ~/.gnus):

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

Also, if you want to take advantage of using gmail’s SMTP server (so gmail keeps track of your sent mail), you can use the following settings:

(setq message-send-mail-function 'smtpmail-send-it
      smtpmail-starttls-credentials '(("" 587 nil nil))
      smtpmail-auth-credentials '(("" 587 "" nil))
      smtpmail-default-smtp-server ""
      smtpmail-smtp-server ""
      smtpmail-smtp-service 587
      smtpmail-local-domain "")

Alternatively, it could be googlemail on the port 465, notably if you have an email not

(setq message-send-mail-function 'smtpmail-send-it
      smtpmail-starttls-credentials '(("" 465 nil nil))
      smtpmail-auth-credentials '(("" 465 "" nil))
      smtpmail-default-smtp-server ""
      smtpmail-smtp-server ""
      smtpmail-smtp-service 465
      smtpmail-local-domain "")

NOTE: You will need starttls, which is used to set up the SSL encrypted connection to the GMail server. This is contained in the “gnutls-bin” package on earlier versions of debian and ubuntu. With later versions (at least Ubuntu 9.10), starttls is in its own package, and the “gnutls-bin” package is not needed. If you don’t have starttls installed, you’ll get a (rather generic) “smtpmail-send-it: Sending failed; SMTP protocol error” error message.

NOTE: (Pointed out by ChristofHarper) You can also store your password in the smtpmail-auth-credentials line, but this means that you’ve got to be more careful when sharing config files with other people.

NOTE: It seems that the above settings (which are what Google recommends) don’t work for some people. Another possibility is to use port 25, and then use ~/.authinfo to convert it back to 587, thus circumventing some code which was getting confused about SMTP through a non-25 port. To do this, replace all occurrences of 587 with 25 in the above snippet, and add the following line to your ~/.authinfo (see GnusAuthinfo and GnusEncryptedAuthInfo):

machine login password secret port 587


machine login password secret port 465

If you don’t wish to store your password there, just omit the “password secret” altogether and you’ll be prompted when you send an email.

NOTE for MS Windows users: Recent emacs or gnutls-cli may choke. Possible remedy is explained here. This is confirmed to work on Emacs from bazaar built with gcc 4.6.2 on Windows XP SP 3. The following is the exact command added

    (setq tls-program '("C:/PROGRA~1/Git/bin/openssl.exe s_client -connect %h:%p -no_ssl2 -ign_eof"))

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

“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 ""
             :port 995
             :user ""
             :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 the user name must include – 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:
  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 with proto POP3 and options no dns
 user '' 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


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:

    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 =
    remoteuser =
    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 "")
    (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

By default, the mail you send from Gnus is not copied to the Gmail server, so if you open the folder “Sent mail”, you won’t see it. You will only see mail sent from the web interface.

TODO: how to store sent mail in the server? (See below.)

A workaround can be CCing yourself whenever you send a mail. With this approach you’ll get a copy which is reflected on the server as well. Moreover, you’ll be the sender of these copies which makes it easy to define a view including only these messages. To use this solution, write this into your .gnus.el file:

(setq gnus-posting-styles
	 ("CC" "")
         (address ""))))

Actually, the problem seems to be solved if you send mail via gmail’s smtp server - at their “Recommended IMAP client settings” they say:

“Do NOT save sent messages on the server. If your client is sending mail through Gmail’s SMTP server, your sent messages will be automatically copied to the [Gmail]/Sent Mail folder.”


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.

To really delete, type B DEL (gnus-summary-delete-article), but beware: you’ll have to delete it from the Trash or Spam folder for it to really delete it. Otherwise, it will only remove the label from the message. I suggest writing a script (probably relying on Message-ID) to find the same message in the trash and delete that copy.

Moving an email to the trash will fail to remove the Inbox label[1]. The solution is to make Gnus locate the message in [Gmail]/All Mail with the same Message-ID as the one in INBOX. Delete the one in the Inbox and move the one in All Mail to the trash. Crocky, but the only solution unless Gmail fixes this on their end. Anyone who has the skill to write this script is welcome to do it.

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 “” and “[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

*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”?


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!)


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.


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 "")
 				 (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 not work in virtual groups. If you want to search on all your mails, you should add the folder ‘All Mail’.

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" "")
         (address ""))
	((header "to" "")
         (address ""))
	((header "cc" "")
         (address ""))
	((header "cc" "")
         (address ""))))

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


Gmail provides a chat interface which uses the XMPP (Jabber) protocol; therefore you can use Emacs Jabber (see JabberEl or BitlBee) to chat with your contacts and with anyone who has a Jabber account.

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