Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

OK...

What is the format for a .forward file?
I saw a posting about sending e-mail to a perl script, and now I want to know how!
So, what is the format of a .forward file??
In the code anyone might give me, can you show me how I would specify that the e-mail be sent to a script called 'mail.pl'?

Thanks ahead.

Replies are listed 'Best First'.
Re: .forward
by jbert (Priest) on Apr 20, 2000 at 17:04 UTC
    Danger Will Robinson!

    Remember - any script which is invoked in response to a received email AND has as one of its possible actions "send an email" should only be written if you have thought things through *very* carefully.

    Why? Mail loop.
    Send an email. Something happens (mail bounces? You get back a non-delivery message, which is a whole new message to process, so we send another mail. That bounces, so we get back a non-delivery message. Ooh - an incoming mail, I'll send a message. That bounces. Ouch.

    Autoresponders are hard to write correctly if you don't have a reasonable amount of experience with email. There are also tools (the 'vacation' program on most unices) to help you do this right, anyway.

    Ditto filtering incoming mail. Locking mail files is great fun and hard to do right. You can lose mail easily this way. Specialised programs like 'procmail' work very hard to do this right.

    The insidious thing about the above is that you can do all the testing in the world and not show up any problems.

    Then your autoresponder manages to get an email from another autoresponder and the world melts down.

    Yours, a patronising, cynical, wizened, email bod

RE: .forward
by Anonymous Monk on Apr 20, 2000 at 16:01 UTC
    From man forward: As with the aliases(4) file, mail messages can be forwarded to another host or given to programs for further processing. The following is an example of the vacation program. Assuming that the user's name is myra, create a .forward file and add the following line:
    \myra, "|/usr/bin/vacation myra"
    The previous example forwards mail to myra (the backslash prevents an accidental aliasing loop), and also sends a copy of the message to the vacation program.
Re: .forward
by btrott (Parson) on Apr 20, 2000 at 03:01 UTC
    I believe it's either an address or a pipe to a script. There may be more possibilities, but you don't need them for this purpose.

    In your case, you'd want to put the following into your .forward:

    |/home/foo/mail.pl
    where /home/foo/ is replaced, of course, by the path to your script.

    In the script, then, you can just read the message from STDIN. Look at the thread in question for more info.

      Further to the above. The ~/.forward file permissions are significant if others have write access it will be not work as the address would be considered unsafe. A .forward file record with a preceding \<user name> will stop any further aliasing stop mail does bounce around. e.g. \<user_name>, |/home/user_name/bin/perl_prog For more info try man sendmail man aliases | forward
        Sorry about that how lost comments! How is this filtered? Makes me look a bigger fool than usual I'll try this, <CODE> ~/.forward file record example \user_name, |path/command <\CODE>