It would help if you include the non-working code that you have
so far, with descriptions of error messages that you get.
If all you need is appending messages to a file, you don't need
Perl to do that. A simple mail alias defined in /etc/aliases
(or the corresponding NIS/NIS+ table, if you use that) or
in the user's .forward file will suffice, using the following
format:
"|/bin/cat > /file/to/append.txt"
or simply
"/file/to/append.txt"
Remember that if the alias is defined in /etc/aliases or other
system table, the program gets executed as root (daemon in
some systems?), so you need to make sure the file has correct
permissions. You could also pipe it to a setuid/setgid program,
and then make sure the file again has appropriate permissions.
If you need to do some pre-processing on the message before appending
it, then you need to pipe it to a program, and that is where
Perl could be useful. Take a look at the
Mail::Internet
package for mail manipulation utilities. Assuming your program
leaves the (possibly) modified message on STDOUT, you need
an alias like this:
"|/your/program.pl > /file/to/append.txt"
in which case again the file gets written by root/daemon. If your
program open the file for writing internally, then you
only need
"|/your/program.pl"
and make sure the setuid/setgid settings of your program match
the permissions on the file.
|