From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Embed Image in Email Content

Hello,

 

I am using SMTP Email Send File.vi to send email using LabVIEW. I am planning to add a png/bmp image as an email attachment and was wondering if it can be inserted in the email content. This way, the attachment does not have to be double-clicked to be opened, but can rather be viewed directly with the email.

 

Thanks.

0 Kudos
Message 1 of 9
(5,005 Views)

The setting that's keeping you from placing HTML code (and therefore an image) into the message is found in NI_SMTPEmail.lvlib:SMTP Email MIME Text Content-Type.vi.  There is a string input that contains "text/plain" which specifies that your message is converted to UTF-8.  If you change this to "text/html" you can put straight HTML into your message text and use an <img> tag.  The only caveat to this with your situation is that you have to have the image hosted somewhere before you can use it in this tag.  However, there are several free image hosting sites that you can use.

 

Since these are VIs included in LabVIEW though, you will probably want to make a copy of the library and make the changes there.  This isn't a big change but still better to be safe.

Alex Person
NI-RIO Product Support Engineer
National Instruments
Message 2 of 9
(4,984 Views)

Thanks, Alex.

 

I will check out the html format for email.

 

I had a question regarding the caveat that you mentioned:

"The only caveat to this with your situation is that you have to have the image hosted somewhere before you can use it in this tag.  However, there are several free image hosting sites that you can use."

 

The image is basically a plot generated in LabVIEW that is converted to bmp that I plan to include in the email. Do I still need to have it hosted somewhere? Thank you.

0 Kudos
Message 3 of 9
(4,975 Views)

If you want to actually embed the image in the email you have to use the  HTML <img> tag as discussed above.  This tag requires that you provide the source of the image as a URL so that it has something to point to when displayed to the end user.  There may be some way out there to embed the image without hosting it, but this is the solution I was able to get to work.

 

If you need to find one of the free hosting sites, just search for "free image hosting".  ImageShack, Photobucket, and TinyPic are some of the sites I am familiar with.

Alex Person
NI-RIO Product Support Engineer
National Instruments
0 Kudos
Message 4 of 9
(4,964 Views)

Thanks again, Alex.

 

I was able to embed the image in the email per your suggestion. The embedded image can be viewed in the email in Outlook. However, the same email in webmail shows a red X (image does not get displayed).

 

I am using the following tag:

<img src="smiley.gif" alt="" />

 

I was wondering if there was something that I might have missed. Comments/suggestions are welcome. Thank you.

 

0 Kudos
Message 5 of 9
(4,910 Views)
I believe that has something to do with the email client.  Try right-clicking on the red X and see if you have an option to show the image.  If that works, look for some client settings for allowing images.
Alex Person
NI-RIO Product Support Engineer
National Instruments
0 Kudos
Message 6 of 9
(4,879 Views)

Can i get code?

 

with html tag i couldn't get results.

 

 

0 Kudos
Message 7 of 9
(4,032 Views)

You could try embedding the image as a base64 encoded string in the html: 

 

<img alt="Embedded Image" src="data&colon;image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA..." />

 

Take the png file (or another file type...you'll need to change the meta type), base64 encode the contents and then put it after the comma.


LabVIEW Champion, CLA, CLED, CTD
(blog)
0 Kudos
Message 8 of 9
(4,024 Views)

Hi, I know this is an old post and I'm sorry for resurrecting it, but I'm having "red X" problems too. Has anyone found solution to this one?

0 Kudos
Message 9 of 9
(3,039 Views)