Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

display image in email body

anilkp
Kilo Contributor

Hi All, 

We have a requirement to display an image in email body (Not as attachment). Image displays properly when i preview email in service now but image is not seen in customer mail box. 

Below is the logic currently used in email script - url is reference to sys_attachment table where image is located. 

<img src=' + url + '>'

This is not able to fetch image from sys_attachment & load it on to email. 

Kindly let me know how to implement this scenario. 

Thanks. 


Regards,

Anil KP 

 

1 ACCEPTED SOLUTION

Better create a business rule on insert on Attachment table when content type is Image/JPEG that copies the attachment to image (db_image) table & then use the above script.

View solution in original post

11 REPLIES 11

Better create a business rule on insert on Attachment table when content type is Image/JPEG that copies the attachment to image (db_image) table & then use the above script.

Hi Jaspal, I tried from db_image to send attachment on body of email & is working fine. Thanks for the info. 

can you please guide to insert on image field of db_image table from sys_attachment. I tried couple of ways but it is copying as attachment to db_image not to field

 

 

 

Hi Anil,

 

Another approach & quicker one would be to get the base64 of the attachment record & then use it in mail script in format below.

var base64is='onlineconvertedvalue';//this value would be long
template.print('<img src="'+base64is+'">');

sys_attachment_doc stores the base64 for each attachment from sys_attachment table.You can GlideRecord sys_attachment_doc table in your mail script along with sys_attachment & get the corresponding base64 in format above. I tested the same & it worked.

 

Let me know if you need any help on this further as the solution above should work.

Hi Jaspal,

thank you for the tip. I've had similar requirement and I used your solution, though I needed to add more parameters in src:

src='data:image/jpeg;base64, LzlqLzRBQ...<!-- base64 data -->' 

Mohit Kaushik
Mega Sage
Mega Sage

Hi There,

There is an easiest way to add image in email notification. You can embed it in source code of html email body. There you need to provide the name of the image stored in your instance.

For example

<img src="name of image with extension as saved in your instance" width="47" height="48" />.

click on highlighted source code link.

find_real_file.png

 

find_real_file.png

Then it will show the image in email body as shown below:

find_real_file.png

 

Please mark this answer as correct and helpful if it  resolved your query. And helpful alone if it led you in right direction.

 

Thanks,

Mohit Kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)