Email with jpg picture embedded - inline

Hi -

The below code works perfectly for e-mailing HTML embeded with JPG picture

sendmail -t <<EOT
TO: ABC.TO@abc.com
FROM: ABC.FROM@abc.com
SUBJECT: Embed image test
MIME-Version: 1.0
Content-Type: multipart/related;boundary="XYZ"
--XYZ
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body bgcolor="#ffffff" text="#000000">
<img src="cid:part1.06090408.01060107" alt="">
My HTML Text Here
Bye
</body>
</html>
--XYZ
Content-Type: image/jpeg;name="banner.jpg"
Content-Transfer-Encoding: base64
Content-ID: <part1.06090408.01060107>
Content-Disposition: inline; filename="banner.jpg"
$(base64 banner.jpg)
--XYZ--
EOT

I changed the code to execute sendmail from command prompt - It is not working - Here is the changed code (named it as testhtml.sh)

Mime-Version: 1.0
From: ABC.FROM@abc.com
Subject: Embed image test
Content-Type: multipart/related;boundary="XYZ"
--XYZ
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body bgcolor="#ffffff" text="#000000">
<img src="cid:part1.06090408.01060107" alt="">
My HTML Text Here
Bye
</body>
</html>
--XYZ
Content-Type: image/jpeg;name="banner.jpg"
Content-Transfer-Encoding: base64
Content-ID: <part1.06090408.01060107>
Content-Disposition: inline; filename="banner.jpg"
$(base64 banner.jpg)
--XYZ--

And here is the command I am executing -

cat testhtml.sh | sendmail -t "ABC.TO@abc.com"

Any idea why this is not working?

Any shell expansion ( $(base64 banner.jpg) ) and/or parameter substitution doesn't happen when you cat a file.

Do you really need to use this way? or you just want to supply the recipients from the command line?

Ok.

Actually my recipient list is huge (that is passed in as a variable) and also HTML, I wanted to keep it in a seperate file - so thought of using it that way.

If I use CAT, I don't need to disturb my older code as well.

Any other options?

I am confused. You have supplied the recipient on the command line you posted.
Where is the variable coming from? Are you calling this script from some other script?

Please post the complete scenario.

Really the code would be like this -

while IFS= read -r line
do
        cat $SCRIPTDIR/mailtype1html.sh | sendmail -t "$line"
done <"$file"

May be you can change your original version as

sendmail -t <<EOT
TO: "$@"
FROM: ABC.FROM@abc.com
SUBJECT: Embed image test
MIME-Version: 1.0
Content-Type: multipart/related;boundary="XYZ"
--XYZ
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body bgcolor="#ffffff" text="#000000">
<img src="cid:part1.06090408.01060107" alt="">
My HTML Text Here
Bye
</body>
</html>
--XYZ
Content-Type: image/jpeg;name="banner.jpg"
Content-Transfer-Encoding: base64
Content-ID: <part1.06090408.01060107>
Content-Disposition: inline; filename="banner.jpg"
$(base64 banner.jpg)
--XYZ--
EOT

And call it as

$SCRIPTDIR/original.sh $(tr '\n' ' ' < $file)

Or, you can pass the recipients file as the command line

sendmail -t <<EOT
TO: $(tr '\n' ' ' < $1)
..
..
EOT

And call it as

$SCRIPTDIR/original.sh $file