5

I have a bunch of scripts on an IBM AIX server's crontab that call the mail command to send myself an e-mail, kinda like this:

$ mail -r [email protected] -s "Results for `hostname`" [email protected] <<EMAILCONTENT
Results of execution of command $COMMAND on `hostname`:

`cat /home/myon/executionresults.txt`
EMAILCONTENT

I intend to put a script that has something like this in a production environment, and as a result I'm trying to find a way to set mail headers using AIX's /usr/bin/mail so that the mails that come from Production arrive to my inbox as high priority. Migrating to Perl's Mail package would take a while, so it preferentially has to be with the standard mail command. I couldn't find an option to specify a mail header neither on mail nor on sendmail (which from what I gathered receives any option that mail can't already parse, in this case the -r).

Any idea of how to set headers this way?

EDIT: Thanks for the answer :3 here's how it worked, reworked so that it looks a bit more like the exhibit above:

$ sendmail -i -- [email protected] <<EMAILCONTENT
From: [email protected]
To: [email protected]
Importance: High
Subject: Results for `hostname`

Results of execution of command $COMMAND on `hostname`:

`cat /home/myon/executionresults.txt`
EMAILCONTENT

1 Answer 1

5

Sendmail: Sending email with custom headers

You can generate any header when you send using sendmail.
[ Sendmail fills missing important headers ]

FILE=/home/myon/executionresults.txt
HOSTNAME=`hostname`
cat - $FILE <<EMAILCONTENT | /usr/sbin/sendmail -i -- [email protected]
Subject: Results for $HOSTNAME
To: [email protected]

Results of execution of command $COMMAND on $HOSTANME:
------------------------------------------------------
EMAILCONTENT

P.S. In such "no strict checks" script with generated dynamic headers DO NOT use -t command line option

1
  • Worked just fine with sendmail :3 methinks I'm going to use it for Production. Not like I need to change much.
    – RAKK
    Commented Sep 13, 2013 at 19:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .