Sendmail with header and footer logo in HTML body

Hello,

I need help with my script that will send email via sendmail command that will shows both the header and footer logo once the recepient receive the email (e.g. MS Outlook). When I tested to ran the script it will successfully send the email BUT UNFORTUNATELY it doesn't displayed the logos as expected. What shows was there's NO logo showed up in the Header location, and the logo showed up in the Footer location was the header logo image.

Below are the scripts, thusly:

*** In my sendTest.sh ***

#!/bin/bash
DIR=/var/images
export MAILTO="junix88@gmail.com"
export SUBJECT="Test sendmail html format with logo both header and footer"
export BODY="/var/www/testcid.html"
export MAILPART=`uuidgen` # ***this will gen mailpart  unique id
export MAILPART_BODY=`uuidgen` # ***this will gen mailpart_body id
export ATTACH="$DIR/headerLOGO.jpg"
export ATTACH1="$DIR/footerLOGO.jpg"
(
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-Type: text/html; charset=UTF-8"
echo "Content-transfer-encoding: us-ascii"
echo "Content-Disposition: inline"
cat $BODY
# echo "--$MAILPART_BODY--"
echo "--$MAILPART"
echo 'Content-Type: image/jpeg; name="'$(basename $ATTACH)'"'
echo "Content-Transfer-Encoding: uuencode"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
echo ""
echo "--$MAILPART"
echo 'Content-Type: image/jpeg; name="'$(basename $ATTACH1)'"'
echo "Content-Transfer-Encoding: uuencode"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH1)'"'
echo ""

(uuencode $ATTACH $(basename $ATTACH) && uuencode $ATTACH1 $(basename $ATTACH1))
echo "--$MAILPART--"
) > catout.out
cat catout.out | /usr/sbin/sendmail $MAILTO

*** In my testcid.html ***

<html>
<head>
<title>NOTIFICATION</title>
</head>
<body>
<center>   <img border=1 src="cid:headerLOGO.jpg" alt=headerLogo />
<p><h4>RE: xxxxx</h4></p>
  <p>abcdefghijlsfdklslslsls<br/>
     asdfewrsafsdfdsfs<br/></p>
  <p>Thank You.</p></td>
  <p>L</p>
<center><img src="cid:footerLOGO.jpg" alt=footerLogo/></center>
</center>
</body>
</html>

I do appreciate for anyone could help me on this to figure out and correct my scripts.

Thanks in advance for your help.

Regards,

Lawrence

Can you show us the exact raw text of the broken email you received?

Hi Corona688,

Thanks for a quick reply. Below are the actual email that I received when I ran the bash script as shown:

On the footer location, this image logo below should supposedly displayed, to wit:

Please let me know if you need other info/logs to help me figure out my script.

Thanks once again.

Regards,

Lawrence

I mean the raw email text, headers and HTML and all... not a screenshot...

Hi Corona,

Good day!

Sorry just replied back.

Below is the full email headers kindly take a look.

Delivered-To: junix88@gmail.com
Received: by 10.28.180.70 with SMTP id du3csp28344vdc;
        Fri, 3 May 2013 10:44:27 -0700 (PDT)
X-Received: by 10.210.60.65 with SMTP id q50mr9658836yhd.188.1367603067278;
        Fri, 03 May 2013 10:44:27 -0700 (PDT)
Return-Path: <root@host01-thesis1.project.ad>
Received: from HOST02-THESIS1-PROJECT.AD (36.86.158-98.q9.net. [98.158.86.36])
        by mx.google.com with ESMTPS id m28si8122623yha.241.2013.05.03.10.44.26
        for <junix88@gmail.com>
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Fri, 03 May 2013 10:44:27 -0700 (PDT)
Received-SPF: neutral (google.com: 98.158.86.36 is neither permitted nor denied by best guess record for domain of root@host01-thesis1.project.ad) client-ip=98.158.86.36;
Authentication-Results: mx.google.com;
       spf=neutral (google.com: 98.158.86.36 is neither permitted nor denied by best guess record for domain of root@host01-thesis1.project.ad) smtp.mail=root@host01-thesis1.project.ad
Received: from HOST02-THESIS1-PROJECT.AD (HOST02-THESIS1-PROJECT.AD [127.0.0.1])
 by HOST02-THESIS1-PROJECT.AD (8.14.3/8.14.3/SuSE Linux 0.8) with ESMTP id r43HiNMW002715
 for <junix88@gmail.com>; Fri, 3 May 2013 17:44:25 GMT
Received: (from root@localhost)
 by HOST02-THESIS1-PROJECT.AD (8.14.3/8.14.3/Submit) id r43HiNf2002714
 for junix88@gmail.com; Fri, 3 May 2013 17:44:23 GMT
Date: Fri, 3 May 2013 17:44:23 GMT
From: root <root@host01-thesis1.project.ad>
Message-Id: <201305031744.r43HiNf2002714@HOST02-THESIS1-PROJECT.AD>
To: junix88@gmail.com
Subject: Test sendmail html format with logo both header and footer
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="82edbbc8-cc85-48a9-906f-89e3467b2b7c"
--82edbbc8-cc85-48a9-906f-89e3467b2b7c
Content-Type: multipart/alternative; boundary="ede42cda-1888-4160-8319-93dcb233c5db"
--ede42cda-1888-4160-8319-93dcb233c5db
Content-Type: text/html; charset=UTF-8
Content-Transfer-encoding: us-ascii
Content-Disposition: inline
<head>
<title>NOTIFICATION</title>
</head>
<body>
<center>   <img border=1 src="cid:headerLOGO.jpg" alt=headerLogo />
<p><h4>RE: xxxxx</h4></p>
  <p>abcdefghijlsfdklslslsls<br/>
     asdfewrsafsdfdsfs<br/></p>
  <p>Thank You.</p></td>
  <p>L</p>
<center><img src="cid:footerLOGO.jpg" alt=footerLogo></center>
</center>
</body>
</html>
--ede42cda-1888-4160-8319-93dcb233c5db
Content-Type: image/jpeg; name=headerLogo.jpg
Content-Transfer-Encoding: uuencode
Content-Disposition: attachment; filename="headerLogo.jpg"
--ede42cda-1888-4160-8319-93dcb233c5db
Content-Type: image/jpeg; name=footerLogo.jpg
Content-Transfer-Encoding: uuencode
Content-Disposition: attachment; filename="footerLogo.jpg"
begin 755 headerLogo.jpg
M_]C_X``02D9)1@`!`0$`8`!@``#_VP!#``(!`0(!`0("`@("`@("`P4#`P,#
M`P8$!`,%!P8'!P<&!P<("0L)"`@*"`<'"@T*"@L,#`P,!PD.#PT,#@L,#`S_
MVP!#`0("`@,#`P8#`P8,"`<(#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,
M#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`S_P``1"``E`H`#`2(``A$!`Q$!_\0`
M'P```04!`0$!`0$```````````$"`P0%!@<("0H+_\0`M1```@$#`P($`P4%
:
:
:
MHHH`****`"BBB@`HHHH`****`"BBB@`HHHH`****`"BBB@`HHHH`****`/_9
`
end
begin 755 footerLogo.jpg
M_]C_X``02D9)1@`!`0$`8`!@``#_VP!#``(!`0(!`0("`@("`@("`P4#`P,#
M`P8$!`,%!P8'!P<&!P<("0L)"`@*"`<'"@T*"@L,#`P,!PD.#PT,#@L,#`S_
MVP!#`0("`@,#`P8#`P8,"`<(#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,
M#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`S_P``1"`!V`7$#`2(``A$!`Q$!_\0`
:
:
:
M-/2U$)2ZEB&0OG7DTI3(V_*68E>#V(P>1S6S118#'_X0VP\H(RW<H\MX\RWD
MTC8<Y(W,Q;J`1S\N,C%7])TR/2+3R8GN'0,3F>=YG_[Z<D_K5FBF`4444`%%
M%%`!1110`4444`%%%%`!1110`4444`%%%%`!1110`4444`%%%%`!1110`444
M4`%%%%`!1110`4444`%%%%`!1110`4444`%%%%`!1110`4444`%%%%`!1110
'`4444`?_V0``
`
end
--ede42cda-1888-4160-8319-93dcb233c5db
--ede42cda-1888-4160-8319-93dcb233c5db--
--82edbbc8-cc85-48a9-906f-89e3467b2b7c--

Thanks in advance for your help.

Regards,

Junx Lawrence

Hello,

I'm new to shell scripting. Anyone could help me on my unresolve issues. Do really need to make it work as expected.

Thank you.

L

Hi,

Anyone tried to figured out my posted issues.

Help is very much appreciated. I'll just wait.

Thanks,
L

Here is a code that I wrote for sending:

  • HTML mail body
  • 1 JPEG file inline (not attachment)
  • 1 GIF file inline (not attachment)

Please note the MIME headers that I used:

{
        echo "From: from@domain.com"
        echo "To: to@domain.com"
        echo "MIME-Version: 1.0"
        echo "Subject: Email Subject"
        echo "Content-Type: multipart/mixed; boundary=\"FILEBOUNDARY\""


        echo "--FILEBOUNDARY"
        echo "Content-Type: multipart/alternative; boundary=\"MSGBOUNDARY\""


        echo "--MSGBOUNDARY"
        echo "Content-Type: text/html; charset=iso-8859-1"
        echo "Content-Disposition: inline"
        echo "<html><body>"
        echo "<font face=verdana size=2>Header Image</font><br>"
        echo "<img src=\"cid:myjpeg\" /><br>"

        echo "<font face=verdana size=2>Footer Image</font><br>"
        echo "<img src=\"cid:mygif\" /><br>"
        echo "</body></html>"
        echo "--MSGBOUNDARY--"


        echo "--FILEBOUNDARY"
        echo "Content-Type: image/jpeg"
        echo "Content-Disposition: inline; filename=\"image_1.jpg\""
        echo "Content-Transfer-Encoding: uuencode"
        echo "Content-Id: <myjpeg>"
        uuencode image_1.jpg image_1.jpg


        echo "--FILEBOUNDARY"
        echo "Content-Type: image/gif"
        echo "Content-Disposition: inline; filename=\"image_2.gif\""
        echo "Content-Transfer-Encoding: uuencode"
        echo "Content-Id: <mygif>"
        uuencode image_2.gif image_2.gif
        echo "--FILEBOUNDARY--"

} | /usr/lib/sendmail -t

Modify as per your requirement. I hope this helps.

1 Like

Hello Yoda,

Good morning!

Very much appreciated your prompt reply on my post yesterday. I'll try your suggested solution and we'll keep you posted.

Thanks much.

Cheers,

JL

---------- Post updated at 12:42 PM ---------- Previous update was at 11:13 AM ----------

Hi Yoda,

You're a GENIUS! It's worked! flawlessly :slight_smile:

I'm currently working now on html file without hardcoding the html code within the bash script. Because when I cat the html file WITHIN it doesn't shows both the jpg and gif file. Hope I'll be able to figure this out.

Once again, thank you very much for your help.

sidenote: I close this post as RESOLVED.

Cheers,

JL

1 Like