old-www/LDP/LG/issue30/tag_vacation.html

359 lines
14 KiB
HTML

<!--startcut ======================================================= -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<META NAME="generator" CONTENT="lgazmail v1.1pre8">
<TITLE>The Answer Guy 30: auto response for email ? </TITLE>
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#A000A0"
ALINK="#FF0000">
<!--endcut ========================================================= -->
<H4>"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <hr> <P>
<!-- =============================================================== -->
<H1 align="center"><A NAME="answer">
<img src="../gx/dennis/qbubble.gif" alt="" border="0" align="middle">
<a href="./index.html">The Answer Guy</a>
<img src="../gx/dennis/bbubble.gif" alt="" border="0" align="middle">
</A></H1> <BR>
<H4 align="center">By James T. Dennis,
<a href="mailto:linux-questions-only@ssc.com">linux-questions-only@ssc.com</a><BR>
Starshine Technical Services,
<A HREF="http://www.starshine.org/">http://www.starshine.org/</A> </H4>
<p><hr><p>
<H3><img src="../gx/dennis/qbub.gif" alt="(?)" width="50" height="28"
align="left" border="0">auto response for email ?</H3>
<p><strong>From Ted via the
<A HREF="http://www.ch4549.org/lust/lusthome.html">L.U.S.T</A> List
on 04 Jun 1998
<!-- begin body -->
<BR><BR>
Whatever you do, don't do this if you are on a mailing list. Think about
the consequences...
<br><br>
Ted the Lurker
</strong></p>
<blockquote><img src="../gx/dennis/bbub.gif"width="50" height="28" alt="(!)"
align="left" border="0">
Ted, when replying to L.U.S.T. messages,
please remove the extraneous quoting.
</blockquote>
<p><strong><em><font color="#003366"
><img src="../gx/dennis/qbub.gif"width="50" height="28" alt="(?)"
align="left" border="0">
Hi,
<br><br>
How does one set up <TT>sendmail</TT> 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 ?
<br><br>
Thanks,
<br>Jyh-shing Chen
</font></em></strong></p>
<blockquote><img src="../gx/dennis/bbub.gif"width="50" height="28" alt="(!)"
align="left" border="0">
Normally one doesn't set up '<TT>sendmail</TT>' to do the
automated response. Normally one would put in a
<TT>.forward</TT> file with something like:
<blockquote><code> "| /usr/local/bin/vacation...."
</code></blockquote>
(or something like that).
<br><br>
There is an old program named "<TT>vacation</TT>" (written by
Eric Allman, author of <TT>sendmail</TT>) 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 "<TT>Precedence: bulk</TT>" 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.
<br><br>
(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 <TT>vacation</TT> defaults to an eight day limit
between responses).
<br><br>
That would be one way one <EM>might</EM> do it.
<br><br>
However, this is Linux and there are even better ways.
Most Linux distributions default to '<TT>sendmail</TT>' as the
MTA (mail transport agent) and use <TT>procmail</TT> as the MDA
(mail delivery agent). (You presumably use <TT>elm</TT>, <TT>pine</TT>,
<TT>MH</TT>, or whatever you like as your MUA --- mail user agent).
<br><br>
'<TT>procmail</TT>' is a "mail processing package" consisting of a
few small programs that you call upon via your own <TT>.procmailrc</TT>
scripts. I wrote an
<A HREF="http://www.linuxgazette.com/issue14/">article</A>
about them for Linux Gazette about a year ago. You can still find it,
and some hot links, at the
<A HREF="http://www.linuxgazette.com/">http://www.linuxgazette.com/</A>
web site.
<br><br>
The <TT>procmail</TT> documentation is a bit confusing so let me offer
a couple of quick notes: <TT>procmail</TT> is a very simple scripting
language. A <TT>procmail</TT> program consists of a list of "recipes"
When an item arrives (is delivered via <TT>procmail</TT>) the
<TT>procmail</TT> binary traverses the script from the top, scanning
for the beginnings of recipes (usually starting with a line
like):
<blockquote><code>:0
</code></blockquote>
... or
<blockquote><code>:0 B
</code></blockquote>
(where <TT>B</TT> is a "flag" --- and there are several of those which
mean different things).
<br><br>
The rest of each recipe consists of some number of "conditions"
(patterns) and <EM>one</EM> "action" (disposition). Each of the
condition lines is of the form:
<blockquote><code>* ^From:.*foo...
</code></blockquote>
... where <TT>^From:.*foo...</TT> 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 <TT>B</TT> flag on the
recipe line or you can put flags on your condition lines
using a syntax like: <TT>* B ?? $PATTERN</TT> (where you replace
<TT>$PATTERN</TT> with the regex for your pattern).
<br><br>
All of the conditions which are logically AND'ed for each
recipe --- so something like:
<blockquote><code>:0
<br>* ^From: joe.*
<br>* ^Precedence: bulk
</code></blockquote>
... would match mail that was from joe (in this case <EM>any</EM>
joe at <EM>any</EM> address) AND had a header indicating that is
was of "bulk" precedence.
<br><br>
After any/all of your condition lines, in a given recipe
you have an action line. The actions you can take are:
<dl><dd>"file it"
<br>"forward it"
<br>"pipe it into a program" (such as an autoreply 'bot).
</dl>
To "forget it" you just "file it" to <TT>/dev/null</TT>. 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 <TT>~/Mail</TT> directory (??). (Normally you'll have a
<TT>MAILDIR</TT> variable set. You can assign and reference variables
in <TT>procmail</TT> in pretty much the same ways as in <TT>sh</TT>
(Bourne shell)).
<br><br>
A name that refers to a directory will cause <TT>procmail</TT> 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: <TT>foo/.</TT> then procmail will write the messages
into the <TT>$MAILDIR/foo/</TT> directory using an MH compatible name
and format.
<br><br>
To forward your mail you start the action line with a "<TT>!</TT>"
(bang) and simply give it an address. Be <EM>very</EM> careful
about forwarding to any address that might have its own
<TT>procmail</TT> or other forwarding agent attached. Otherwise
you'll create a mail loop. For this reason most <TT>procmail</TT>
wizards never use the "<TT>!</TT>" 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).
<br><br>
So, here's how you pipe the message (to forward or autoreply)
You start your action line with a <TT>|</TT> (pipe) symbol and
the rest is just the command line. The procmail suite comes
with a program called '<TT>formail</TT>' (FORmat some MAIL headers).
<br><br>
So if you pipe mail to <TT>formail</TT> with the "<TT>-r</TT>" switch
it will format a "reply" and if you add the <TT>-A</TT> switch it will
"Add" a custom header line (replacing any previously matching header).
<br><br>
Here's an example:
<blockquote><code>:0
<br>* !^FROM_MAILER
<br>* !^FROM_DAEMON
<br>* &lt; 10000
<br>* ^Subject: info
<br>* !^X-Loop: info@starshine.org
<br>| ((formail -rk -A "Precedence: junk" \
<br>-A "X-Loop: info@starshine.org" ; \
<br>echo "Info Request received on:" `date`) \
<br>| $HOME/insert.doc -v file=$DOC/general.info) | $SENDMAIL -t -oi -oe
</code></blockquote>
... 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 "<TT>FROM_MAILER</TT>" and "<TT>FROM_DAEMON</TT>"
patterns are a couple of "magic" patterns that <TT>procmail</TT>
recognizes --- they are actually expanded to some hefty
regexes internally.
<br><br>
... in other words, this action line is doing alot more than
most auto-reply. The point is that I can use <TT>formail</TT> to
create the reply headers (which it gets by filtering the
header as <TT>procmail</TT> 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 <TT>sendmail</TT> (the
full, local path to which is conveniently stored in the
<TT>$SENDMAIL</TT> variable). The <TT>-t</TT> switch on
'<TT>sendmail</TT>' means:
"Take the 'to' addresses from the headers on your standard
input" --- this is the safest and cleanest way to pipe
messages into <TT>sendmail</TT>.
<br><br>
That's a short course on <TT>procmail</TT>. 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.
<br><br>
One last note: There are 5 man pages on <TT>procmail</TT>, 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).
<br><br>
The weighted scoring stuff is high wizardry --- I don't use
it. The examples are mostly suitable for cut and paste.
<br><br>
Keep in mind that you can call all sorts of programs,
not just '<TT>formail</TT>' --- so you could write a simple
<TT>procmail</TT> script call on a "<TT>sendpage</TT>" program when
someone really important sends you mail about something "really
important"
<br><br>
Also '<TT>formail</TT>' has the <TT>-D</TT> 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 <TT>-r</TT>
(don't deliver to this folder if this is a duplicate according
to the <TT>Message-ID:</TT> header line). Both meanings have
quite a bit to do with "duplication" --- but are much different
in usage.
<br><br>
If you subscribe to lists, like L.U.S.T, I suggest <TT>procmail</TT>
for auto sorting your mail. When you want to add auto replies
--- even if you're just going to call on Eric's '<TT>vacation</TT>'
program, you should add that as a recipe <EM>after</EM> any
procmail sorting (and spam filtering) and <EM>with</EM> the
<TT>* !^FROM_</TT> and <TT>X-Loop:</TT> patterns. That will prevent
auto-replies to mailing lists that don't put in their
"<TT>Precedence: Bulk</TT>" line, and that might be from daemons and
mailers (other auto responders) that '<TT>vacation</TT>' doesn't "see"
('<TT>procmail</TT>' and '<TT>formail</TT>' are more
recent and benefit from a few more years of experience with
Internet "standards drift").
<br><br>
One of these days I may write a whole book on procmail.
It would be pretty short (like the O'Reilly '<TT>vi</TT>' 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
<A HREF="http://www.imada.ou.dk/~blackie/dotfile/">TDG</A> (the
dotfile generator)
provides a menu-driven (GUI?) front end to creating <TT>.procmailrc</TT>
files --- among many others. That would probably be a good
place to look for more info. <em>[He may have read about it in
<A HREF="http://www.linuxgazette.com/issue17/dotfile.html"
>issue 17's article</a> -- Heather]</em>
</blockquote>
<!-- end body -->
<!--================================================================-->
<P> <hr> <P>
<H5 align="center"><a href="http://www.linuxgazette.com/copying.html"
>Copyright &copy;</a> 1998, James T. Dennis <BR>
Published in <I>Linux Gazette</I> Issue 30 July 1998</H5>
<P> <hr> <P>
<!--================================================================-->
<table width="98%"><tr valign="center" align="center">
<td rowspan="3"><A HREF="./lg_answer30.html"><IMG
SRC="../gx/dennis/answernew.gif"
ALT="[ Answer Guy Index ]"></A></td>
<td><A HREF="tag_SCOkeys.html">SCOkeys</A></td>
<td><A HREF="tag_chroot.html">chroot</A></td>
<td><A HREF="tag_dosemu-db.html">dosemu-db</A></td>
<td><A HREF="tag_NTauth.html">NTauth</A></td>
<td><A HREF="tag_cdr.html">cdr</A></td>
<td><A HREF="tag_3270.html">3270</A></td>
<td><A HREF="linux-questions-only@ssc.comport.html">comport</A></td>
</tr><tr valign="center" align="center">
<td><A HREF="tag_lilostop.html">lilostop</A></td>
<td><A HREF="tag_emulate.html">emulate</A></td>
<td><A HREF="tag_ppadrivers.html">ppadrivers</A></td>
<td><A HREF="tag_database.html">database</A></td>
<td><A HREF="tag_vacation.html">vacation</A></td>
<td><A HREF="tag_nullmodem.html">nullmodem</A></td>
<td><A HREF="tag_lockups.html">lockups</A></td>
</tr><tr valign="center" align="center">
<td><A HREF="tag_gzipC.html">gzipC</A></td>
<td><A HREF="tag_newlook.html">newlook</A></td>
<td><A HREF="tag_c500.html">c500</A></td>
<td><A HREF="tag_solprint.html">solprint</A></td>
<td><A HREF="tag_vc1shell.html">vc1shell</A></td>
<td><A HREF="tag_memleak.html">memleak</A></td>
<td><A HREF="tag_tvcard.html">tvcard</A></td>
</tr></table>
<P> <hr> <P>
<!--================================================================-->
<A HREF="./index.html"><IMG SRC="../gx/indexnew.gif"
ALT="[ Table Of Contents ]"></A>
<A HREF="../index.html"><IMG SRC="../gx/homenew.gif"
ALT="[ Front Page ]"></A>
<A HREF="lg_bytes30.html"><IMG SRC="../gx/back2.gif"
ALT="[ Previous Section ]"></A>
<A HREF="./vrenios.html"><IMG SRC="../gx/fwd.gif"
ALT="[ Next Section ]"></A>
<!--startcut ======================================================= -->
</body>
</html>
<!--endcut ========================================================= -->