Adding image as email header

meghanareddy206
Tera Contributor

I'm trying to add an image as email header in Servicenow using mail scripts calling from email template. I'm able to see the image perfectly but its not responsive when delivered to outlook. When I maximize the screen in outlook, header breaks in middle of the page. When I try the same code in any html editor, its working fine.The actual size of the image is bytes: 492,543 width = 1122, height = 280.  Any help will be appreciated.

Mail script code for header:

(function runMailScript(current, template, email, email_action, event) {
var link = gs.getProperty('glide.servlet.uri');
var div = "<head><style>.responsive {width: 100%; height: auto;}</style></head><img class='responsive' src='" + link + "sampleimg.png'/>";
template.print(div);
})(current, template, email, email_action, event);

calling this in an email template below:

${mail_script:header}
 
Hi ${approver.name},
 
${sysapproval.request} created by ${sysapproval.opened_by} is now pending your approval.
 
 
${mailto:mailto.approval.ritm} | ${mailto:mailto.rejection.ritm}
 
${mail_script: ritm_email_approval}
  
${mail_script:snow_footer} 
3 REPLIES 3

Roger Poore
Tera Guru

Have you tried it like this (adding body tag and closing html)?

var div = "<html><head><style>.responsive {width: 100%; height: auto;}</style></head><body><img class='responsive' src='" + link + "sampleimg.png'/></body></html>";

Also, have you tried viewing the source code when opening the e-mail in Outlook? Outlook uses Word for rendering e-mails. Viewing the source should give you an indication as to what's going on.

Thanks roger, I have used the same code above, but still no luck. Also, able to see the outlook source, its displaying the same code. what else we can check from outlook?

Outlook source code for image:

<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><div>
<div><style>.responsive {width: 100%; height: auto;}</style><img class="responsive" src="cid:sampleimg.png@SNC.237a32a24e823212"></div>
</div>
<div>
<div>&nbsp;</div>
</div>

What if you reversed your process?  I mean, in Outlook, compose an HTML e-mail like you want it to look for the notification.  Then transfer that to your mail script. 

Otherwise, you could try something like http://emailframe.work/ which was made to help with this type of thing. Use those templates rather than what you've been doing.