Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell script embed multiple image with sendmail

I'm using following script to embed multiple image on a mail using sendmail function.

sendmail -t <<EOT
TO: [email protected]
FROM: [email protected]
Cc: [email protected]
SUBJECT: Phobos Report 
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=""><br/>
<img src="cid:part2.06090408.01060107" alt=""><br/>
<img src="cid:part3.06090408.01060107" alt="">
</body>
</html>

--XYZ
Content-Type: image/jpeg;name="rag1.jpg"
Content-Transfer-Encoding: base64
Content-ID: <part1.06090408.01060107>
Content-Disposition: inline; filename="rag1.jpg"

$(base64 rag1.jpg)

--XYZ

Content-Type: image/jpeg;name="rag2.jpg"
Content-Transfer-Encoding: base64
Content-ID: <part2.06090408.01060107>
Content-Disposition: inline; filename="rag2.jpg"

$(base64 rag2.jpg)

--XYZ

Content-Type: image/jpeg;name="rag3.jpg"
Content-Transfer-Encoding: base64
Content-ID: <part3.06090408.01060107>
Content-Disposition: inline; filename="rag3.jpg"

$(base64 rag3.jpg)
--XYZ--
EOT

Here only the first image getting embedded. And all the others are failed to get added. Those two images are added as text based attachment. How can I add multiple images on this script?

like image 427
sugunan Avatar asked Sep 26 '22 22:09

sugunan


1 Answers

It is an old question, but I think it deserves an answer anyway.

The problem with your code is that you are putting empty lines between the MIME boundary and the MIME headers of the last two images, as here:

--XYZ

Content-Type: image/jpeg;name="rag2.jpg"
Content-Transfer-Encoding: base64
Content-ID: <part2.06090408.01060107>
Content-Disposition: inline; filename="rag2.jpg"

This is not allowed. You should correct your code and delete those empty lines in two places, as follows, here:

--XYZ
Content-Type: image/jpeg;name="rag2.jpg"
Content-Transfer-Encoding: base64
Content-ID: <part2.06090408.01060107>
Content-Disposition: inline; filename="rag2.jpg"

and here:

--XYZ
Content-Type: image/jpeg;name="rag3.jpg"
Content-Transfer-Encoding: base64
Content-ID: <part3.06090408.01060107>
Content-Disposition: inline; filename="rag3.jpg"

Empty lines are allowed before the boundary line, which means that they will be part of the preceding body, where they are usually harmless (but I can make up contexts where they wouldn’t be. It’s not your case, however.)

It’s best never to put extra empty lines on either side of MIME boundaries. Of course, this is not about the empty line needed before the first MIME boundary, where it separates the MIME header.

like image 146
Dario Avatar answered Sep 30 '22 07:09

Dario