sed or awk removes attachment in email

Hi

We have a requirement to send email using shell script.email should have html body and pdf attachment. We used uuencode for attaching files and sendmail option to acheive and it is working fine. However custoemr wants to make body of email slightly dynamic. E.g dear customer in html file should be Dear John .. html is currently static and we tried editing using sed , awk etc.

So when we edit the html file and replaced the string we are received body of email as expected but attachment is not there ,,when we just static html file it does work fine

Kindly suggest your inputs

Hi Harish7586,

It's always best to post your actual code and text if you want help (so we are not guessing).

For example, here is a similar question asked at our forums:

html format email with attachment in unix

Notice how they actually post their code.

In your case, Hi Harish7586, you have not posted anything we can examine with our own eyes. So please post your code and text examples if you need assistance.

Thanks.

#!/usr/bin/ksh

parse_file()
{
["$*" = ""] && return
[ ! -f "$1"] && return
eval echo "\"$(cat $1 | sed '87s/Member/Harish R/g')\""
}

export MAILTO="abc@xyz.com"
export SUBJECT="Test PDF for Email"
export BODY="/export/user/abc.html"
export NEW_BODY="/export/user/temp_content.html"
export ATTACH="/export/use/file1.pdf"
export MAILPART='uuidgen' ## Generates Unique ID
export MAILPART_BODY='uuidgen' ## Generates Unique ID
export AWK=/usr/xpg4/bin/awk
#echo "sed -i '87s/Member/Harish R/g' "$BODY" > "$NEW_BODY""
cp $BODY $NEW_BODY
#cat "$NEW_BODY" |/usr/bin/awk -v awkfrom="Member" -v awkto="Harish R" '{gsub(awkfrom,awkto)}' > $NEW_BODY
#$(echo cat $NEW_BODY | $AWK -v awkfrom="Member" -v awkto="Harish R" '{gsub(awkfrom,awkto)}')
#sed -i '87s/Member/Harish R/g' "$BODY" > "$NEW_BODY"
(
 echo "From: $MAILFROM"
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo "Content-Type: multipart/mixed; boundary=\"$MAILPART\""
 echo ""
 echo "--$MAILPART"
 echo "Content-Type: multipart/alternative; boundary=\"$MAILPART_BODY\""
 echo ""
 echo "--$MAILPART_BODY"
 echo "Content-Type: text/plain; charset=ISO-8859-1"
 echo "You need to enable HTML option for email"
 echo "--$MAILPART_BODY"
 echo "Content-Type: text/html; charset=ISO-8859-1"
 echo "Content-Disposition: inline"
 $(parse_file $NEW_BODY)
#cat $NEW_BODY
 echo "--$MAILPART_BODY--"
 
 echo "--$MAILPART"
 echo 'Content-Type: application/pdf; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: uuencode"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 echo ""
 #uuencode -m $ATTACH $(basename $ATTACH)
 uuencode $ATTACH $(basename $ATTACH)
 echo "--$MAILPART--"
 
)| /usr/sbin/sendmail $MAILTO

Please find my code above. I tried editing the body html file. At the moment it works if we just give cat $NEW_BODY however when i edit the file using sed or awk then it fails to send attachment but content is as expected

I suggest to you, for debugging purposes, that you pipe the output of your script to a file (or to standard out) instead of to the sendmail command.

Do this for both cases (with your awk or sed commands and without) and compare the two outputs.

Post back your results, and do not forgot to use code tags around your code and input/output text.

You will have a much easier time to debug if you look at the results of your script and compare the working and not working results, side by side, instead of just sending the output to sendmail .

That is what I would do.....