VERSICH

Integrating External Images into Emails | NetSuite

integrating external images into emails | netsuite

When utilizing NetSuite, businesses frequently create email templates that may include external images. This guide explains how to correctly embed these images while avoiding common mistakes.

Often, companies use tags linked to the file cabinet for images. However, there are instances where images are externally sourced or generated temporarily. This can lead to the following errors:

  • Blank HTML <img> src attribute
  • <img> src unsetting in email or <img> src not setting

These issues generally arise when the source is formatted as a data URI, appearing like this:

data:image/png;base64,iVBORw0KGgoAA ... teOv==

How to Embed External Images in NetSuite Emails

The primary method of eliminating this error is to reconstruct the data URI as a file in NetSuite so that the <img> source attribute can point to a new string. Given a data URI, this is done with the following functions:

  • Split the data URI into the base64 string and its data content using something like:

const base64String = datauri.split(',')[1];

  • Grab the NetSuite folder to hold the image and the userID to build the URL:

const userId = runtime.getCurrentUser().id;

  • Save the converted data into a NetSuite file object matching the original data URI description
  • For instance, if the original URI was “data:image/png” then use the following

const netsuiteFile = file.create({ name: 'qrcode' + userId + '.png', fileType: file.Type.PNGIMAGE, //Based on image type contents: base64String , description: "QR Code", encoding: file.Encoding.UTF8, isOnline: true, folder: QRCODE_FOLDER_ID }).save();

  • Load the created image file to retrieve external URL info. 

const imageFile = file.load({id: netsuiteFile});

  • Retrieve the host domain to complete the URL

const accountDomian = url.resolveDomain({ hostType: url.HostType.APPLICATION, });

  • Build the URL string for the <img> src attribute to call

    <img src="{'https://'" +="" accountdomian="" imagefile.url}="">

If the generated file needs to be deleted, run a scheduled script to clean the file cabinet and inform users of their time window.