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.*spammer.you.despise@spamhaven.com
* !^FROM_MAILER
* !^FROM_DAEMON
* !^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."\
   echo\
   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
fallback

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

______________________

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix