From Ted via the
on 04 Jun 1998
Whatever you do, don't do this if you are on a mailing list. Think about the consequences...
Ted the Lurker
Ted, when replying to L.U.S.T. messages, please remove the extraneous quoting.
How does one set up sendmail for automatically responding to an email indicating that one is out of the office and will be responding to the incoming emails at a later date ?
Normally one doesn't set up 'sendmail' to do the automated response. Normally one would put in a .forward file with something like:(or something like that).
There is an old program named "vacation" (written by Eric Allman, author of sendmail) which can be used for this purpose. You can read the man page for it if you like. It does some checks to prevent replies to mailing lists (looks for a "Precedence: bulk" header line) and system accounts (Mailer-Daemon, Postmaster, etc). It also maintains a "cache" of addresses to which the "vacation message" (or other auto-response) has been sent to prevent spurious (and very annoying) duplicate responses to the same address.
(In other words, if you really are "on vacation" and someone routinely copies you on some sort of mail, usually as part of a workgroup list, they only need to hear about it once. I think vacation defaults to an eight day limit between responses).
That would be one way one might do it.
However, this is Linux and there are even better ways. Most Linux distributions default to 'sendmail' as the MTA (mail transport agent) and use procmail as the MDA (mail delivery agent). (You presumably use elm, pine, MH, or whatever you like as your MUA --- mail user agent).
'procmail' is a "mail processing package" consisting of a few small programs that you call upon via your own .procmailrc scripts. I wrote an article about them for Linux Gazette about a year ago. You can still find it, and some hot links, at the http://www.linuxgazette.net/ web site.
The procmail documentation is a bit confusing so let me offer a couple of quick notes: procmail is a very simple scripting language. A procmail program consists of a list of "recipes" When an item arrives (is delivered via procmail) the procmail binary traverses the script from the top, scanning for the beginnings of recipes (usually starting with a line like):... or
:0(where B is a "flag" --- and there are several of those which mean different things).
The rest of each recipe consists of some number of "conditions" (patterns) and one "action" (disposition). Each of the condition lines is of the form:... where ^From:.*foo... is a regular expression that is checked against portions of the mail message that is currently "in hand" (as it were). Usually your patterns will only be applied to the messages headers. If you use the B flag on the recipe line or you can put flags on your condition lines using a syntax like: * B ?? $PATTERN (where you replace $PATTERN with the regex for your pattern).
All of the conditions which are logically AND'ed for each recipe --- so something like:... would match mail that was from joe (in this case any joe at any address) AND had a header indicating that is was of "bulk" precedence.
* ^From: joe.*
* ^Precedence: bulk
After any/all of your condition lines, in a given recipe you have an action line. The actions you can take are:
To "forget it" you just "file it" to /dev/null. In general any filename on the action line will be consider to be a mail folder. Any filename with no path elements will be considered standard mbox (elm/pine compatible) folder under your ~/Mail directory (??). (Normally you'll have a MAILDIR variable set. You can assign and reference variables in procmail in pretty much the same ways as in sh (Bourne shell)).
- "file it"
"pipe it into a program" (such as an autoreply 'bot).
A name that refers to a directory will cause procmail to write each message into a separate file in that directory (this is called a "directory folder"). If you use a folder of the form: foo/. then procmail will write the messages into the $MAILDIR/foo/ directory using an MH compatible name and format.
To forward your mail you start the action line with a "!" (bang) and simply give it an address. Be very careful about forwarding to any address that might have its own procmail or other forwarding agent attached. Otherwise you'll create a mail loop. For this reason most procmail wizards never use the "!" forwarding operator --- they pass the message to a pipe, adding their own headers and formatting the message to the new address (still forwarding it -- but with some checks and changes in the headers).
So, here's how you pipe the message (to forward or autoreply) You start your action line with a | (pipe) symbol and the rest is just the command line. The procmail suite comes with a program called 'formail' (FORmat some MAIL headers).
So if you pipe mail to formail with the "-r" switch it will format a "reply" and if you add the -A switch it will "Add" a custom header line (replacing any previously matching header).
Here's an example:... note this one is unusually complex since I am "keeping" the senders message, checking if the whole thing is over 10K, appending the date on which I received the message, and inserting (via a two line awk script named "insert.doc") a response. Also those "FROM_MAILER" and "FROM_DAEMON" patterns are a couple of "magic" patterns that procmail recognizes --- they are actually expanded to some hefty regexes internally.
* < 10000
* ^Subject: info
* !^X-Loop: firstname.lastname@example.org
| ((formail -rk -A "Precedence: junk" \
-A "X-Loop: email@example.com" ; \
echo "Info Request received on:" `date`) \
| $HOME/insert.doc -v file=$DOC/general.info) | $SENDMAIL -t -oi -oe
... in other words, this action line is doing alot more than most auto-reply. The point is that I can use formail to create the reply headers (which it gets by filtering the header as procmail passes the header and body of the mail into the pipe). I can then ship the results of that to some other process (to do other processing on the body or whatever) and finally passing that all to a copy of sendmail (the full, local path to which is conveniently stored in the $SENDMAIL variable). The -t switch on 'sendmail' means: "Take the 'to' addresses from the headers on your standard input" --- this is the safest and cleanest way to pipe messages into sendmail.
That's a short course on procmail. The tutorial I wrote for Linux Gazette is even more basic than that --- so if I rattled through some of that too fast: go read it.
One last note: There are 5 man pages on procmail, one for the binary, one on the rc file syntax (the programming language) one that's full of examples, and another on the "weighted scoring" extensions (which allow you to add and subtract values to a "weight" using various conditional patterns, which can be sensitive to how many times a pattern appears in a message --- so you could automatically descriminate against messages that were more than have "quoted" lines).
The weighted scoring stuff is high wizardry --- I don't use it. The examples are mostly suitable for cut and paste.
Keep in mind that you can call all sorts of programs, not just 'formail' --- so you could write a simple procmail script call on a "sendpage" program when someone really important sends you mail about something "really important"
Also 'formail' has the -D switch, which means one thing if used in conjunction with -r (the combo means, "Don't duplicate" our reply -- like vacation; where it checks for the ). It means something else when used without the -r (don't deliver to this folder if this is a duplicate according to the Message-ID: header line). Both meanings have quite a bit to do with "duplication" --- but are much different in usage.
If you subscribe to lists, like L.U.S.T, I suggest procmail for auto sorting your mail. When you want to add auto replies --- even if you're just going to call on Eric's 'vacation' program, you should add that as a recipe after any procmail sorting (and spam filtering) and with the * !^FROM_ and X-Loop: patterns. That will prevent auto-replies to mailing lists that don't put in their "Precedence: Bulk" line, and that might be from daemons and mailers (other auto responders) that 'vacation' doesn't "see" ('procmail' and 'formail' are more recent and benefit from a few more years of experience with Internet "standards drift").
One of these days I may write a whole book on procmail. It would be pretty short (like the O'Reilly 'vi' book, or their one on "termcaps"). It's a very powerful utility that currently is passed on as an "oral tradition" among sysadmins and Unix hacks. I think I heard that TDG (the dotfile generator) provides a menu-driven (GUI?) front end to creating .procmailrc files --- among many others. That would probably be a good place to look for more info. [He may have read about it in issue 17's article -- Heather]