You will have to generate a multipart body resembling the raw mail below. This is how gmail composes such a message. I don't have a ready made script for you.
The Content-Type line is part of the mail headers, the rest is mail body.
Content-Type: multipart/related; boundary="00000000000065025f05f70a8645"
--00000000000065025f05f70a8645
Content-Type: multipart/alternative; boundary="00000000000065025c05f70a8644"
--00000000000065025c05f70a8644
Content-Type: text/plain; charset="UTF-8"
before
[image: favicon.png]
after
--
signature
--00000000000065025c05f70a8644
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>before</div><div><img src=3D"cid:ii_lfbkwr450" alt=3D=
"favicon.png" width=3D"64" height=3D"64"><br></div><div>after<br></div><div=
><br></div><div><div><div dir=3D"ltr">-- <br>signature</div></div></div></d=
iv>
--00000000000065025c05f70a8644--
--00000000000065025f05f70a8645
Content-Type: image/png; name="favicon.png"
Content-Disposition: inline; filename="favicon.png"
Content-Transfer-Encoding: base64
Content-ID: <ii_lfbkwr450>
X-Attachment-Id: ii_lfbkwr450
iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAAAXNSR0IArs4c6QAAAARnQU1BAACx
[...some data removed...]
biBkAAAAAElFTkSuQmCC
--00000000000065025f05f70a8645--