need help with my sendmail script

hi all,

i'm trying to use sendmail to send a message in html format with attachments but having some issues with the attachments. below is my code.

ATTACH1="/export/home/adshocker/attach.prog"
ATTACH_NAME1=${ATTACH1##*/}
echo "ATTACH_NAME1=$ATTACH_NAME1"
ATTACH2="/export/home/adshocker/attach.sh"
ATTACH_NAME2=${ATTACH2##*/}
echo "ATTACH_NAME2=$ATTACH_NAME2"
(
 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="'${ATTACH_NAME1}'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'${ATTACH_NAME1}'"'
 uuencode $ATTACH1 $ATTACH1
 echo 'Content-Type: application; name="'${ATTACH_NAME2}'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'${ATTACH_NAME2}'"'
 uuencode $ATTACH2 $ATTACH2
 echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO

when i get the message, i only get the first attachment and when i open it, it's sort of encrypted. can anyone help me with this.

i'm using solaris.

thanks.

You need an empty line to end the MIME header. Also, man uuencode (linux) is not quite the same as man base64 (linux). My suggested changes are in red, below:

1 Like

hi,

thank you for your help. i've manage to get my code working now with some minor changes. unfortunately we don't have base64 so i went with uuencode instead. below is my final and working code:

SUBJECT="TEST"
BODY="/export/home/adshocker/body.htm"
ATTACH1="/export/home/adshocker/attach.prog"
ATTACH_NAME1=${ATTACH1##*/}
echo "ATTACH_NAME1=$ATTACH_NAME1"
ATTACH2="/export/home/adshocker/attach.sh"
ATTACH_NAME2=${ATTACH2##*/}
echo "ATTACH_NAME2=$ATTACH_NAME2"
(
 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"
 echo
 cat $BODY
 echo
 echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'${ATTACH_NAME1}'"'
 echo "Content-Transfer-Encoding: uuencode"
 echo 'Content-Disposition: attachment; filename="'${ATTACH_NAME1}'"'
 echo
 uuencode $ATTACH1 $ATTACH1
 echo
 echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'${ATTACH_NAME2}'"'
 echo "Content-Transfer-Encoding: uuencode"
 echo 'Content-Disposition: attachment; filename="'${ATTACH_NAME2}'"'
 echo
 uuencode $ATTACH2 $ATTACH2
 echo
 echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO