Command line/Script to send E-mail with HTML body and binary attachment

I apoligize for the cross-post but I'm not getting much in the way of help in the dummies forum:

I'm trying to script sending an e-mail message on an AIX 5.x server with the following requirements:

  1. command line switch to specify file name containing message body in HTML format
  2. command line switch to specify file name of a binary attachment
  3. command line or input file to specify recipients (both to:, cc: and bcc
  4. command line to specify From: address
  5. command line to specify mail subject (subject text may include spaces)

I've tried every combination redirecting and piping uuencode and mail/mailx you could ever come up with with no luck.

The stumbling block is the HTML message body. Attaching a binary file to a text message body is a no brainer but I have to have the message body in HTML because we are using formatted tables.

Any help would be greatly appreciated.

Thanks.

This works on a linux box which has uuencode --base64 so you may have to modify for AIX.

#!/usr/bin/ksh

export MAILTO="spam@ebay.com"
export SUBJECT="Report"
export BODY="/tmp/report.html"
export ATTACH="/tmp/sample.pdf"
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo "Content-Type: text/html"
 echo "Content-Disposition: inline"
 cat $BODY
 echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 uuencode --base64 $ATTACH $(basename $ATTACH)
 echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO

Thanks. Tested with it after modifying for AIX uuencode syntax. Didn't work but we are really close.

This particular html document is actually a "Save As" from a Microsoft Word document and it appears that Microsoft puts some additional HTML kung-fu in the header that that doesn't fully comply with the RFC.

Any chance you can give me the correct mime syntax to use a Microsoft Word document for the message body instead of the HTML?

BTW, the correct AIX uuencode syntax for base 64 is:
uuencode -m input_file output_file

Try if the below works for u......

##################################

TIMESTAMP=`date +"%m-%d"`
mailx -s "$TIMESTAMP - Hi" abc@att.com << EOF
`/usr/bin/uuencode /tmp/Test.pdf Test.pdf`
Hi,

See if u able to catch file....

EOF

##################################\

Cheers
ArB