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 myon@hakugyokuro.gk -s "Results for `hostname`" myon@hakugyokuro.gk <<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 -- myon@hakugyokuro.gk <<EMAILCONTENT
From: myon@hakugyokuro.gk
To: myon@hakugyokuro.gk
Importance: High
Subject: Results for `hostname`

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

`cat /home/myon/executionresults.txt`
EMAILCONTENT
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 -- myon@hakugyokuro.gk
Subject: Results for $HOSTNAME
To: myon@hakugyokuro.gk

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.