Tips from The Answer Guy

Learn how to block mail your mail and tighten your security from The Answer Guy.
Netscape Mail Block

I need to refuse to accept e-mail from a particular person. How can I configure Netscape and/or CND1.0 to bounce the person's mail back to them? —Mitch, Mobile, Alabama

And the Answer Is...

I'd use procmail, a little programming language written specifically for processing mail. CND uses procmail as the “local delivery agent” by default. This means that sendmail passes any mail for a local account to procmail, and then lets procmail do the final delivery to your mail box, /var/spool/mail/your_login_name. At the same time, procmail checks for a .procmailrc file in your home directory, and does some ownership and permissions checks on it for you.

The author of a .procmailrc file can specify a variety of settings and clauses which are called “recipes”, and can also modularize the file by using a variety of INCLUDE directives. Here's a simple example that should get you started:

:0 hr
* ^From.*
* !^X-Loop: ${USERNAME}i@`hostname`"
| (formail -r -A"X-Loop:
${USERNAME}@`hostname`" \
-A"Precedence: junk";\
   echo "Your mail is not welcome here."\
   echo "Please don't mail me again."\
   cat ~/your.signature.or.flame

The :0 marks this as a new recipe—each new recipe starts with this line. The h and the r on that line are flags tell procmail which parts of the message to hand to your action line (i.e., the one that starts with a pipe, |).

  • h says: “Give me the header.”

  • r says: “Treat the incoming data as raw.”

The r flag is given to prevent your response from failing if the sender has failed to put a blank line at the end of his message.

The following four “star” lines in the script are conditions. The first specifies that the header will show that the message is “from” your spammer, that is, your unwanted sender. This address will exactly match any “from” or “From:” line that contains your target e-mail address. The next two lines of the script ensure that you don't respond to daemons and mailers (mailing lists). The last * line, which you should fill in with your user name and host name, ensures that your don't respond to your own response. Those three conditions are included to protect your script from being tricked into undesirable actions. Consider them to be the minimum overhead on any auto-responders that you write.

The next line of the script, which starts with a “|” pipe character, describes the action to take. In procmail there are three types of actions:

  1. A file name specifies an mbox (elm, pine or mailx compatible) folder in which to store the message.

  2. A directory name specifies an mh or mmdf folder for mail storage. mh and mmdf use different naming schemes for the messages in their folder directories, but you don't need to worry about this difference unless you use one of their mail user agents.

  3. A ! (bang) line specifies an e-mail address to which the message is to be bounced. A | (pipe) line specifies that the message is to be filtered through a local program.

formail is a program that comes with the procmail package. It “formats mail headers”. This particular formail command formats a “reply” (-r) header, and adds two additional header lines—a standard “Precedence: junk” line and a personal “X-” line. The RFC822 spec allows you to use the X- line to embed custom information into a header. It is also in the formail command line that you prevent an attack by routing your response back into your own script, i.e., a mail loop.

The echo and cat statements after the formail line provide output that is appended after the mail header and that becomes the body of your response. You can add additional echo lines or you can create a file and use cat to add it here.

If you are new to procmail (which is almost certain given your question—auto-responders are some of the first things that procmail users learn), you may be nervous about breaking something and losing some of your mail. To protect yourself you will want to start your .procmailrc with the following simple recipe:

:0 c

This recipe, if it is the first recipe in the script, appends a copy of every incoming message to a file named fallback in your ~/Mail directory by default. You can compare the contents of that folder to your inbox until you are confident that everything is working as you expect.

Please read the procmail and procmailex (examples) man pages for more details. The author, Stephen van der Berg, has also written an automated mail list management package called SmartList that is highly regarded among people that I know who have used it. I like SmartList much better than Majordomo. —Jim


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