Issue to attachment with HTML body

HI Team,

I used below code to get attachment with HTML body. i having21062013.csv file . but i am getting junk .csv file. Can you please help me out.

export MAILTO=rp908@gmail.com.com
export SUBJECT="Test Waiver Code email"
export BODY=test.html
export ATTACH=21062013.csv
EMAIL_BOUNDARY_STRING=Z${RANDOM}${RANDOM}${RANDOM}.${RANDOM}
(
echo "To: $MAILTO"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="${EMAIL_BOUNDARY_STRING}"'
echo '--${EMAIL_BOUNDARY_STRING}'
echo "Content-Type: text/html charset=us-ascii"
echo "Content-Disposition: inline"
cat $BODY
echo '--${EMAIL_BOUNDARY_STRING}'
echo "Content-Transfer-Encoding: base64"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
uuencode $ATTACH $(basename $ATTACH)
) | /usr/sbin/sendmail $MAILTO

---------- Post updated at 02:15 AM ---------- Previous update was at 01:59 AM ----------

hello friend,

need your help!!

The reason why you are getting junk in your attachment is because in the email header you specified base64 for encoding, but you are using uuencode.

Modify below header as highlighted:

echo "Content-Transfer-Encoding: uuencode"

but i am getting blank file now . can you please suggest for this

The script should work after changing the encoding. Make sure the file that you are attaching is in the path where you are running this script.

You can also set xtrace/verbose and check what is happening.

hi,

i have changed as below, still getting empty file.

export BODY=test.html
export ATTACH=27062013.csv
EMAIL_BOUNDARY_STRING=Z${RANDOM}${RANDOM}${RANDOM}.${RANDOM}
(
echo "To: $MAILTO"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="${EMAIL_BOUNDARY_STRING}"'
echo "Content-Transfer-Encoding: uuencode"
echo '--${EMAIL_BOUNDARY_STRING}'
echo "Content-Type: text/html charset=us-ascii"
echo "Content-Disposition: inline"
cat $BODY
echo '--${EMAIL_BOUNDARY_STRING}'
echo "Content-Transfer-Encoding: base64"
#echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"' uuencode $ATTACH $(basename $ATTACH)) | /usr/sbin/sendmail $MAILTO
echo 'Content-Disposition: attachment; filename="'$(basename /rep/p31100/users/repP3ap/jewel/27062013.csv)'"' uuencode $ATTACH $(basename 21062013.csv)) |
 /usr/sbin/sendmail $MAILTO