Sams Teach Yourself Emacs in 24 Hours


Hour 20: Gnus Basics

Previous HourNext Hour

Sections in this Hour:


Setting Up Gnus

To get started with Gnus, you need to insert a few lines in your .Gnus file. The .Gnus file is located in the same place as your .emacs file and serves the same purpose as the .emacs file, with the one exception; the code written into the .Gnus file is configured specifically for Gnus.

You might be in a situation where you want to use Gnus for either news or mail, but not both. In that case, do one of the following:

Server and Backend

Given that the server you want to use is called and you want to use the nnfolder backend, you must insert one of the following into your .emacs file:

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

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

(setq gnus-select-method '(nntp ""))
(setq gnus-secondary-select-methods '((nnfolder "")))

Mail Source

If you want to read mail with Gnus, you have to tell Gnus about where it should fetch your mail from. There are three different ways Gnus can fetch mail for you:

Each of the three methods have options describing the method, as can be seen in Table 20.1

Table 20.1  Options Specifying Where to Fetch Mail



Reading Mail from a File


The path to the file containing the mail.

Reading Mail from a POP Server


This is the name of the server to fetch the mail from.


This is your username on the server.


This is your password on the server (if you haven't specified this, you

will be prompted in the minibuffer).

Reading Mail from a Directory


This is the directory in which the files are located.


This is the suffix for the files. You might, for example, ask procmail to deliver your letters in the Mail directory, and name them with the extension .procmail. Then Gnus reads in these and writes its own copies to the files without the .procmail extension. (Remember: Gnus reads the mail into a file of its very own).

Additional options exist for the POP mail-fetching method. These do, however, require customization beyond the scope of this book. See the Gnus reference manual if this doesn't work for you.

You can tell Gnus to read your mail from several different sources at the same time; for example, if you have your inbox in the ordinary spool directory and you also get mailing lists sorted into a directory, it is possible to get mail from both places. To specify where to get mail from, you must set the variable nnmail-spool-file. This variable is best described with an example:

(setq nnmail-spool-file '(  
   (file :path "/var/spool/mail/blackie")  
   (directory :path "/home/blackie/Mail" :suffix ".procmail")  
   (pop :server "pop.mail.server" :user "Gnus-lover" :password "SeCrEt")  

The first and last lines are simply some Lisp code that needs to be there. The three lines in the middle describe three different places to fetch mail from. The first is from a spool file; the second is from a directory where mail has been delivered into files ending in .procmail. Finally, the third place is a POP server called pop.mail.server, where my username at the server is Gnus-lover, and my password is SeCrEt. Please note the colons in front of the options.

Installing the Mailboxes

When you have told Gnus where to fetch your mail and news, it's time to start Gnus for the first time. But before you do that, please ensure that you are online and that you have some mail in your inbox (given, of course, that you want to read mail with Gnus). To start Gnus, press M-x and type gnus. When Gnus has started up, it reads the information from your news server about which groups exist. The size of this information depends on the number of newsgroups your server offers (the size for my server is approximately 2MB). Don't worry; Gnus does not have to fetch this file each time it starts.

When Gnus has started, you will be subscribed to a few newsgroups, and your incoming mail folder is shown as a group called mail.misc. This can be seen in Figure 20.1.

If you, for some reason, should not be subscribed to your incoming mail boxes, press the caret (^). This brings you to a buffer like the one seen in Figure 20.5.

Figure 20.5
The Server buffer.

In this buffer you can see all your servers (that is, all the different places from which Gnus can fetch mail and news). If you press the Enter key on the backend you use for mail ( nnfolder in Figure 20.5), you get to a buffer like the one seen in Figure 20.6. From this buffer you can subscribe to the mail groups available. (There might be several if you have told Emacs to read mail from a directory; in this case, each file in this directory reflects a mail group.) Subscribing to one of the groups is done by pressing u. (That is, u for unsubscribe--the key is a toggle.)

Figure 20.6
This shows the mail group with the incoming messages.

Sams Teach Yourself Emacs in 24 Hours


Hour 20: Gnus Basics

Previous HourNext Hour

Sections in this Hour: