|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Sysadmin Fight spam with procmail
procmail is standard on most distros
By: Joshua Drake
Mar. 1, 2001 12:00 AM
Q: I use sendmail and a POP mail server on a Linux box. I am desperately looking for a way to filter incoming messages processed by sendmail based on their subject names and enclosure names. I would like to do this to filter spam and potentially dangerous viruses. A: I'm not sure if you are talking about the MTA (Mail Transfer Agent, aka sendmail) or the MUA (Mail User Agent, aka Netscape Mail). However, there are solutions for both. Most graphical clients have built-in filtering that you can use. On the server side, you can use a program called procmail. Procmail is installed by default on most Linux systems, and can be used system-wide or user by user. Procmail is a powerful program that uses recipes to define filtering mechanisms that result in certain actions. For example, you can define a filter that states that any mail coming from the user bgates@microsoft.com is automatically redirected to
:0
* ^From.*bgates@microsoft.com
{
:0
/dev/null
}
All procmail filters are kept in a # # # Begin /etc/procmailrc # #The ORGMAIL variable sets the global mail directory for the system -- in other words, the system mailbox. I have set ORGMAIL to be /var/spool/mail/$LOGNAME where $LOGNAME is the login name of the user.
The As I mentioned, procmail is a very powerful program. Your recipes can be used to generate a slew of useful actions. What if we don't want to send all the email from bgates@microsoft.com to
:0
* ^From.*bgates@microsoft.com
{
:0
antitrust
}
This recipe will cause all email from bgates@microsoft.com to be saved to a file called
:0
* ^From.*bgates@microsoft.com
{
:0
mail/antitrust
}
This recipe will cause the You can write recipes for procmail to support multiple conditions. Let's take the following:
:0
* ^From.*bgates@microsoft.com
* ^Subject:.*competition
{
:0
mail/antitrust
}
As before, we are using the bgates recipe. This time, if we receive email from bgates@microsoft.com that contains the subject "competition," the recipe will take action and move the email to the You can initiate multiple actions within a recipe by doing the following:
:0
* ^From.*bgates@microsoft.com
* ^Subject:.*competition
{
:0 cThe recipe now will forward all email from bgates@microsoft.com with the subject "competition" to justicedept@us.gov, and move the email message to Using multiple recipes within
:0
* ^From.*bgates@microsoft.com
* ^Subject:.*competition
{
:0 cThe first recipe is the one we used for the earlier examples. The second will take any email from sexcity and dump it to As you can see from the above examples, procmail is not difficult, but you'll want to be careful. If you make a mistake in your procmail configuration, you can blow away your entire email configuration. Test each recipe and watch what happens with your email. Once you get it locked down, however, it works great. One last point I need to make is that you must configure sendmail to understand that procmail exists, and to accept procmail as a mailer for the sendmail daemon. Configuring sendmail to use procmail isn't hard, but it's more involved than what the scope of this article will allow. Consult the procmail man pages and the sendmail FAQ for more information. As a side note, sendmail itself provides facilities to aid spam reduction, as well. That's it for this week's Ask the Geek. Reader Feedback: Page 1 of 1
Your Feedback
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
||||||||||||||||||||||||||||||||||||||||||||||||||||