Gnus for Mail and Newsgroups

A tutorial for using and configuring Gnus in Emacs that can make your inbox a cleaner and much more efficient place.
Configuring Gnus for Mail

To set up the Gnus mail feature, add the following lines to your .gnus file:

<pree> ;; Leave these two lines alone. (setq message-send-mail-function 'smtpmail-send-it) (setq send-mail-function 'smtpmail-send-it) ;; Customize the next three lines with your ISP information. (setq smtpmail-smtp-server "smtp.your-isp.com") (setq gnus-secondary-select-methods '((nnml "smtp.your-isp.com"))) (setq smtpmail-local-domain "your-isp.com")

You may have one e-mail address, or you may have several. If you have only one, include this line:

(setq mail-sources '((pop :server "your.pop3server2.com" :user "user" :password "password")))

If you have several, insert the following code to add a line for each e-mail address. They will be fetched in the order that you specify them here. Once fetched, all e-mail is treated more or less the same.

(setq mail-sources '(
                     (pop :server "your.pop3server.com" :user "user" :password "password")
                     (pop :server "your.pop3server2.com" :user "user2" :password "password2")
                     ))

You don't have to include the password field. If you leave it off, though, you will be prompted to enter your password whenever you check for new mail.

Once all this configuration is done, try running Gnus, and it should fetch your mail. All mail will be dumped together into one pseudo-newsgroup. That's not the most helpful way for Gnus to act, but you need to give it more information in order for it to sort your mail intelligently.

Sorting Articles into Categories

Gnus treats your e-mail as one or more newsgroups, which is its power, because it will drop the mail into the groups you specify. Some groups will contain high priority mail; others will contain mailing lists that you only look at occasionally. You should establish a spam group and try and get Gnus to put all your spam there. Finally, there will be a catch-all group that collects the mail that doesn't fit anywhere else.

To create a mail group you have to specify its name and a regular expression. Mail that matches the regular expression will end up in that group.

The following simple example shows two groups, one for mail from ed@telestoconsulting.com and another for all other mail.

 (setq nnmail-split-methods
       '(
         ("mail.me" "^From:.*ed@telestoconsulting\\.com")
         ("mail.other" "")))

The first group, mail.me, will collect any message that has a line beginning with From: (the ^ indicates that this needs to be at the beginning of the line), and then contains any number of other characters, and then the string ed@telestoconsulting.com. (Change this to your own e-mail address, of course).

Note the double slash (\\) in front of the dot between telestoconsulting and com. The double slash is necessary because the period character has a special meaning in Emacs regular expressions--it means zero or more of the following character. That's not what I want here, though; I want to match the string ed@telestoconsulting.com exactly. To let Gnus know I want to match a literal period here, and not the special meaning of period in regular expressions, I need to insert the \\.

Regular expressions can become quite complex. To use a logical OR, parentheses and a vertical bar can be used. But these also need to be preceded by a double slash. For example, to have e-mail from both of my e-mail addresses dropped into the mail.me category, I can enter the following:

("mail.me" "^From:.*\\(ed@telestoconsulting\\.com\\|ejh@idcomm\\.com\\)")

The regular expression now contains a sub-expression, which is delimited with parentheses \\(expression1\\|expression2\\). This line tells Gnus that when the From header is either expression1 or expression2, the mail should go in the me group. This gets a little confusing because expression1 and expression2 both need to contain \\ as they both contain a period. I still want those interpreted literally because it is part of the e-mail address.

The use of the parentheses and logical OR can be applied more than once in the regular expression. In the following example, I have a group called mail.ieee, which I want to use to collect all the incoming messages from IEEE. That includes any messages with IEEE in the address or subject line, as well as any mail from JWest, the local IEEE guy.

("mail.ieee" "^\\(To\\|Cc\\|From\\|Reply-To\\):.*\\(ieee\\|JWest@\\)")

This regular expression looks for a line beginning with either To, CC, From, or Reply-To, followed by a colon, then followed by any number of any other characters (that's the .*), then either ieee or JWest@. (Sometimes JWest sends e-mail about IEEE from his work address, which doesn't have "ieee" in it.)

As you can see, regular expressions can get quite long. If they do, don't insert any line breaks;simply let the line wrap around in the editor. To make sure you can spot e-mail from friends, try this:

("mail.friends" "^From:.*\\(friend@myfriends\\.isp\\.com\\|friend2@myfriend2s
\\.isp\\.com\\|friend3@myfriend3s\\.isp\\.com\\)")

The above regular expression will drop e-mail from three different e-mail addresses into mail.friends. The e-mail addresses are found in the parenthetically delimited list \\(e-mail1\\|e-mail2\\|e-mail3\\). It looks confusing, because once again I have to use a double slash before any period I want taken literally, and each e-mail address contains two such periods.

This is a great one if you get a lot of non-ASCII spam:

("mail.nonascii" "^\\(Subject\\|From\\):.*\\Ca*")

This regular expression tells Gnus to watch out for any e-mails with one or more non-ASCII characters in the subject line.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Gnus for Mail and Newsgroups - HTML?

Anonymous's picture

Can gnus now display mail with html in it? That one problem I found with using it in the past....

Re: Gnus for Mail and Newsgroups

dsaklad's picture

How would you make it easier for nonprogrammers to set up gnus email ?... What's available on the web currently still requires knowledge that once it's set up that knowledge isn't critical to operating gnus email.

For example, I've set up gnus newsgroups. Now, how do I get gnus email set up?... Step by step instructive comments are needed that can be followed by nonprogrammers unfamiliar with the jargon.

oo__ dsaklad@gnu.org

See also
[ http://groups.google.com/groups?as_q=saklad&safe=off&ie=ISO-8859-1&as_ugroup=gnu.emacs.gnus&lr=&as_scoring=d&hl=en ]

How to make gnus email setup automatic or nearly automatic.

dsaklad's picture

How would you make it easier for nonprogrammers to set up gnus email ?... What's available on the web currently still requires knowledge that once it's set up that knowledge isn't critical to operating gnus email.

For example, I've set up gnus newsgroups. Now, how do I get gnus email set up?... Step by step instructive comments are needed that can be followed by nonprogrammers unfamiliar with the jargon.

oo__ dsaklad@gnu.org

See also
[ http://groups.google.com/groups?as_q=saklad&safe=off&ie=ISO-8859-1&as_ugroup=gnu.emacs.gnus&lr=&as_scoring=d&hl=en ]

Re: Gnus for Mail and Newsgroups

Anonymous's picture

Oops...I posted a reply instead of a new comment. Duh! So...How do you handle spam messages that are uuencoded? We are noticing that the spammers have caught on to the word and phrase based delivery rules which we use to eliminate spam. To thwart the delivery rules, they uuencode their messages. Is there a way to first decode the message then pass it to their delivery rules

Re: Gnus for Mail and Newsgroups

Anonymous's picture

Minor correction about regular expressions: A period (.) means "any character" not "any number of the following character." A star (*) means "any number of the _previous_ character".

Re: Gnus for Mail and Newsgroups

Anonymous's picture

How do you handle spam messages that are uuencoded? We are noticing that the spammers have caught on to the word and phrase based delivery rules which we use to eliminate spam. To thwart the delivery rules, they uuencode their messages. Is there a way to first decode the message then pass it to their delivery rules?

Re: Gnus for Mail and Newsgroups -- great article!

Anonymous's picture

I've been using Gnus for about a year. I thought this article was a good general overview of Gnus. Thanks!

Re: Gnus for Mail and Newsgroups -- great article!

Anonymous's picture

I've been using Gnus since 95/96, and have lately tried to get away from it. You know what? It's impossible! I've yet not found any other mail/news client that gives me the same flexibility as Gnus have. Sure, most of the other are better looking, but they dont have the same feature richness as Gnus.

Re: Gnus for Mail and Newsgroups -- great article!

Anonymous's picture

Sylpheed is catching up though (for those that like a GUI MUA)

Re: Gnus for Mail and Newsgroups -- great article!

Anonymous's picture

Can sylpheed do article expiry as this is a major selling pint for gnus for people subscribed to big lists

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState