December 19, 2005

CLI Magic: Introducing rss2email

Author: Joe 'Zonker' Brockmeier

As its name suggests, Aaron Swartz's GPL-licensed rss2email utility converts RSS subscriptions into email messages and sends them to whatever address you specify. Despite the name, it handles Atom feeds as well, so you should be able to use it with just about any feed you like.

Why would you want to receive feed updates in your inbox rather than checking them in a feed reader? Isn't the whole point of feed subscriptions to browse them at your leisure? For the most part, I don't want to receive an email every time one of the feeds I subscribe to is updated -- I have more than 200 subscriptions, so that would fill up my inbox pretty quickly. However, there are a few select feeds I do want to monitor more closely, so I use rss2email to shoot me an email when those are updated.

If you don't subscribe to many feeds, then rss2email might be a better fit for you than a full-blown RSS client. You can receive updates in the comfort of your favorite mail reader without having to set up a feed reader.

Debian users can grab rss2email just by running apt-get install rss2email. The rss2email site has instructions for installing rss2email on other Linux distros and Unix-type platforms. You will need to have Python installed beforehand.

Adding feeds

Once you have rss2email installed, you'll probably want to start by adding a few feeds. This is easy -- just find the feed URL that you want to add and run r2e with the add directive:

r2e add http://www.linux.com/linuxcom.rss

Why, yes, I am shamelessly plugging the Linux.com feed. The first time you add a feed to your list, you may not want to send email messages for all of the existing entries. To prevent this, use the --no-sendoption:

r2e run --no-send

This tells rss2email to run and to update its database of feeds with the existing stories, so that you'll only get email for new stories.

Sometimes you may want to send feeds to different addresses. For example, you may need to send email to your personal email address when a friend updates his Weblog and send email to your work address when there's an update on the SecurityFocus Vulnerabilities feed.

To send email to an address other than the default, add it to the end of the command when you add the feed:

r2e add http://www.securityfocus.com/rss/vulnerabilities.xml me@work

If you're adding feeds with special characters, you can put the URL in quotes to prevent the shell from trying to interpret them. For example, I added a feed from Google News that would alert me to new stories about Linux, but the ampersands in the URL (http://news.google.com/?q=Linux&ie=UTF-8&output=rss) are special characters that will be interpreted by the shell rather than being passed to r2e. To ensure that it's processed correctly, you can add it like so:

r2e add "http://news.google.com/?q=Linux&ie=UTF-8&output=rss"

Automating feeds

While you can run rss2email manually, it's more useful to schedule it to run automatically via a cron job. Run crontab -e to edit your crontab and add this entry:

15 * * * * /usr/bin/r2e run

This will run rss2email every hour at 15 minutes past the hour. Obviously, you can change this to whatever interval suits you best. If you're not familiar with setting up crontab, have a look at Mark Alexander Bain's CLI Magic column on the topic.

Managing feeds

Once you have added a few feeds, you may want to make changes to your subscriptions. To see all of your feeds, run r2e list to generate a list similar to the following:

default email: user@yourdomain.net
1: http://www.newsforge.com/newsforge.rss (default: user@yourdomain.net)
2: http://www.linux.com/linuxcom.rss (default: user@yourdomain.net)

If you want to delete a feed, just use the delete command and the number of the feed:

r2e delete n

Replace n with the number of the feed you want to delete. After running this, r2e will confirm that the feed has been deleted. Also, note that you should run r2e list again before deleting any other feeds, as the list numbers may have changed, and you don't want to delete the wrong feed accidentally.

What happens when you have a dozen feeds set up to go to your work email and you change jobs? You don't need to delete and re-add all your feeds -- you can simply switch your default email address using the email directive:

r2e email new@address

This will change the default email address, but it won't affect any feeds that are being sent to other email addresses. Unfortunately, there doesn't seem to be a way to change the email address if it's not the default, so if you have a set of feeds being sent to a non-default address, you'll have to handle those manually.

Additional configuration

If you want set the default email address, SMTP server, body width of the email, or other parameters, you can set these in rss2email's config.py, which you can find under your home directory in the .rss2email directory.

The Debian packages come with a sample config.py that is well-commented and serves as a good starter config. You can find this in /usr/share/doc/rss2email/examples. If you've installed rss2email using the instructions on the rss2email site site, you won't have a sample config to work with. You can create your own from an empty file, or you can grab the sample Debian config from my site.

I won't cover all of the available configuration parameters, but there are a few I'd like to touch on. The first is the DEFAULT_FROM. This is the email address that updates appear to be coming from. Normally, rss2email will set this to the address for the feed itself, if one is set. Otherwise, it defaults to the DEFAULT_FROM address if that value is set. If you want to change it to something other than the default email address, just pass it the address you'd like to use:

DEFAULT_FROM = "rss@mydomain.com"

To force all feeds to use this address, regardless of whether they have an email address or not, set the FORCE_FROM parameter to 1:

FORCE_FROM = 1

Normally, the date header will be set based on when the mail was sent, as opposed to when the item in the feed was posted. If you'd prefer to have the date reflect when the item was posted, set DATE_HEADER to 1.

One of the things I like about rss2email is that it sends plain-text email by default even when the items themselves are in HTML. If you prefer to receive HTML email, set the HTML_MAIL parameter to 1.

By default, rss2email will not wrap long lines -- but if you'd like to change this, you can set the line length using the BODY_WIDTH parameter. For example, the following will set the width to 72 characters:

BODY_WIDTH = 72

Finally, you may want to send mail from your SMTP server rather than the machine that's running rss2email. You need to set two values for this: set the SMTP_SEND parameter to 1 and set the SMTP_SERVER to your preferred SMTP server:

SMTP_SERVER = "smtp.mydomain.com"

That should get you up and running with rss2email. Be sure to check the man page and rss2email site if you'd like to learn more.

I wouldn't want to use rss2email for all of my feeds, but I find it useful for the handful of feeds I want to stay on top of every day.

Click Here!