Insert an image in HTML mail sent from Shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert an image in HTML mail sent from Shell script
# 15  
Old 01-05-2015
Hi Anji,

What appears in the source of the mail when you run the script with the $(base64 $file) call?
This User Gave Thanks to Skrynesaver For This Post:
# 16  
Old 01-05-2015
Hi Skrynesaver
I get the below when i run the
Code:
$(base64 $file)

Code:
NTM1IGYNCjAwMDAwMDAwMDAgNjU1MzUgZg0KMDAwMDAwMDAwMCA2NTUzNSBmDQowMDAwMDAwMDAw
IDY1NTM1IGYNCjAwMDAwMDAwMDAgNjU1MzUgZg0KMDAwMDAwMDAwMCA2NTUzNSBmDQowMDAwMDAw
MDAwIDY1NTM1IGYNCjAwMDAwMDAwMDAgNjU1MzUgZg0KMDAwMDAwMDAwMCA2NTUzNSBmDQowMDAw
MDAwMDAwIDY1NTM1IGYNCjAwMDAwMDAwMDAgNjU1MzUgZg0KdHJhaWxlcg0KPDwvU2l6ZSAyMDMv
SURbPERDOThEOTcyNDA2ODE3NEE5QzlCREQ1RUFBNEE1Nzc4PjwzNzAyRjU5QzI0MEJCNjQ2OURD
MEFENDdDMUQ2RTNBND5dPj4NCnN0YXJ0eHJlZg0KMTE2DQolJUVPRg0K

Thanks
Anji
# 17  
Old 01-06-2015
Strange, when I try to view the resultant tag in a browser the image seems to be invalid...
Code:
<img src="data:image/jpeg;base64,NTM1IGYNCjAwMDAwMDAwMDAgNjU1MzUgZg0KMDAwMDAwMDAwMCA2NTUzNSBmDQowMDAwMDAwMDAwIDY1NTM1IGYNCjAwMDAwMDAwMDAgNjU1MzUgZg0KMDAwMDAwMDAwMCA2NTUzNSBmDQowMDAwMDAwMDAwIDY1NTM1IGYNCjAwMDAwMDAwMDAgNjU1MzUgZg0KMDAwMDAwMDAwMCA2NTUzNSBmDQowMDAwMDAwMDAwIDY1NTM1IGYNCjAwMDAwMDAwMDAgNjU1MzUgZg0KdHJhaWxlcg0KPDwvU2l6ZSAyMDMvSURbPERDOThEOTcyNDA2ODE3NEE5QzlCREQ1RUFBNEE1Nzc4PjwzNzAyRjU5QzI0MEJCNjQ2OURDMEFENDdDMUQ2RTNBND5dPj4NCnN0YXJ0eHJlZg0KMTE2DQolJUVPRg0K"

---------- Post updated at 11:42 ---------- Previous update was at 10:10 ----------

Just to be sure I tested on my own host...
Code:
 echo \<img src=\"data:image/jpeg\;base64,$(base64  avatar.jpg )\"\> > test.html

produced a test.html file that worked in my browser...
This User Gave Thanks to Skrynesaver For This Post:
# 18  
Old 01-06-2015
Hello Skrynesaver
My bad, the resultant tag was too big so I just copied part of it, I attached it in txt format now..

Also, I tried the exactly how you tested at your end and the image was showing in browser to me aswell

Code:
Picture showing in browser with the below command
DEV_u35731:~/dev> echo \<img src=\"data:image/jpeg\;base64,$(base64  /home/u35731/dev/1.jpg)\"\> > test.html



But, when i try to use that code in my html file and call it in my shell script its not working Smilie , Image not coming up in my email

Code:
Not working the code from mail.html
...
<img width=640 height=147 src="data:image/jpeg;base64,$(base64  /home/u35731/dev/1.jpg)">
...



Thank you
Anji
# 19  
Old 01-07-2015
Hi Anji,

You would have to script creation of the /home/u35731/dev/mail.txt file rather than just using cat to apend it to the mail without interpolation.

Code:
#!/bin/bash
outputFile="/home/u35731/dev/mail.txt"
/home/u35731/bin/gen_mail_txt.sh $outputFile # where gen_mail_txt.sh generates the file including the required image tags.
(
echo "From: donotreply@xyz.com"
echo "To: anji009@xyz.com"
echo "MIME-Version: 1.0"
echo "Subject: Test"
echo "Content-Type: text/html; charset=ISO-8859-15"
echo "Content-Transfer-Encoding: 7bit"
cat $outputFile
) | sendmail -t

This User Gave Thanks to Skrynesaver For This Post:
# 20  
Old 01-07-2015
Thanks Skrynesaver
I tried but didn't work too Smilie
I have a query here.. As you said
Quote:
"You would have to script creation of the /home/u35731/dev/mail.txt file rather than just using cat to apend it to the mail without interpolation"
,
If thats the case then how come the image is displaying in email when i just cat the output mail.txt file in script which has the image tags where as src as url ?

Working code
Code:
<img width=130 height=30 id="Picture_x0020_4" src=http://i.imgur.com/4pGDdQM.gif >

Is this suggestion is for only those images who have the img src as local linux drives ?


Thanks
Anji
# 21  
Old 01-12-2015
<img width=130 height=30 id="Picture_x0020_4" src=http://i.imgur.com/4pGDdQM.gif >

This worked with the images with local location of the image. I am also using the html5 chart for my images.

Last edited by fredharry; 01-12-2015 at 03:52 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A shell script for checking the last image and sending it in attachment to mail

Hello every one. I use mutt : "mpack -s "Test" /home/pi/Pictures/2018-10-05_23_10_40.jpg my_email_addres " to send me a particular picture with the name of the data+jpg in a pictures folder, but this folder I use it for a timelapse proyect with more pictures , and what I need is... (2 Replies)
Discussion started by: maxbcn
2 Replies

2. Shell Programming and Scripting

Embed image to the html script

hi, trying to embed an image to the html file to send out as an email. img src="data:image/jpeg;base64,$(base64 /home/test/abc.jpg but getting error as file not found after it aplies base64 on the file. (8 Replies)
Discussion started by: ATWC
8 Replies

3. Shell Programming and Scripting

Script that gathers specific values from files and puts it into HTML to send e-mail

Hi All, Sorry for long topic here. So the drill goes like that, I need a script which gathers different values from different files/locations. A_CT=`cat a.dat | awk -F'|' '{print $1}' >> report.txt` B_CT=`cat b.dat | awk -F'|' '{print $3}' >> report.txt` C_CT=`cat c.dat | awk -F'|'... (4 Replies)
Discussion started by: shivakid
4 Replies

4. Shell Programming and Scripting

[Solved] Shell script output in HTML or with table like results and mail

Hello, Currently i have a script which will disply the results in plain text format. I want to format the result in more readable format like Making bold headings and format with colors etc. Something like html and send that content as email. Please help me how i can do that. I am using... (10 Replies)
Discussion started by: joy lobo
10 Replies

5. UNIX for Dummies Questions & Answers

Bash script to insert data into an html table

hi, I need to create a bash shell script which picks up data from a text file and in the output file puts it into an html made table. I have to use sed and awk utilties to do this the input text file will contain data in the format: job name para1 para2 para3 para4 para4 1 ... (1 Reply)
Discussion started by: intern123
1 Replies

6. Shell Programming and Scripting

Send mail with rich text / HTML with image

Hi, Is it possible to send mail from my HP-Ux system with images, rich text? I would like to program in such a way that I have my company's logo(.jpg) image attached in the mail geeting triggered. I would like to send a rich text/HTML email instead of plain text mail to the recipients. Is it... (2 Replies)
Discussion started by: rythym05
2 Replies

7. UNIX for Advanced & Expert Users

shellinabox/html help to insert a keypress with an html button

I am trying to use shellinabox as a terminal emulator. Everything is working except there seems to be no way to simulate an F14 button press in shellinabox. I am already embedding shellinabox in an html page so Im am wondering if there is a way to make an html/js button that will pass F14 to the... (0 Replies)
Discussion started by: syadnom
0 Replies

8. Shell Programming and Scripting

background image not loading in newly thrown html page by shell script

I m trying to throw back html page when a file is found.While throwing back html page, the background image is not coming. I am using Apache server.Please suggest how to resolve... #!/bin/ksh echo -e "Content-type: text/html\n\n" echo "<html><head></head><body background=\"/asc/ppp.jpg\">"... (10 Replies)
Discussion started by: ravi18s
10 Replies

9. Shell Programming and Scripting

Script to Convert HTML to MIME mail -- HELP!

Hi: I have writed a script that read a HTML file and convert this in a multipart mime fail to send in a mail. But the result isn't interpreted lika a mime file!! Somebody can see the error??? --------------------------- #! /bin/bash SB=$1 IF=$2 OF=$3 rm -f $OF.b64 ... (7 Replies)
Discussion started by: sushisan
7 Replies

10. AIX

Command line/Script to send E-mail with HTML body and binary attachment

I apoligize for the cross-post but I'm not getting much in the way of help in the dummies forum: I'm trying to script sending an e-mail message on an AIX 5.x server with the following requirements: 1. command line switch to specify file name containing message body in HTML format 2. command... (3 Replies)
Discussion started by: G-Man
3 Replies
Login or Register to Ask a Question