Typologie rule code for Email size? | Community
Skip to main content
Best answer by SushantTrimukheD

@god_prophet,

Please use the below script in control typology rule and this will stop the delivery if the size of the content is more than 35KB.

// JavaScript code to check email size in Adobe Campaign var sg = new StringGroup("nms:core"); var maxSizeInBytes = 35 * 1024; // 35KB = 35 * 1024 bytes var sizeInBytes = 0; // Safely access HTML content length if (delivery && delivery.content && delivery.content.html && delivery.content.html.source) { sizeInBytes += delivery.content.html.source.length; // Add HTML content length } // Safely access text content length if (delivery && delivery.content && delivery.content.text && delivery.content.text.source) { sizeInBytes += delivery.content.text.source.length; // Add text content length } // Log size for debugging logInfo("Delivery size log: Email size (" + (sizeInBytes / 1024).toFixed(2) + " KB)"); // Check if size exceeds limit if (sizeInBytes > maxSizeInBytes) { logWarning("Delivery aborted: Email size (" + (sizeInBytes / 1024).toFixed(2) + " KB) exceeds maximum allowed size of 35 KB."); return false; // Exclude the delivery } return true; // Allow the delivery

 


Let me know if this works.

Thanks

Sushant Trimukhe

1 reply

SushantTrimukheD
SushantTrimukheDAccepted solution
Level 4
June 23, 2025

@god_prophet,

Please use the below script in control typology rule and this will stop the delivery if the size of the content is more than 35KB.

// JavaScript code to check email size in Adobe Campaign var sg = new StringGroup("nms:core"); var maxSizeInBytes = 35 * 1024; // 35KB = 35 * 1024 bytes var sizeInBytes = 0; // Safely access HTML content length if (delivery && delivery.content && delivery.content.html && delivery.content.html.source) { sizeInBytes += delivery.content.html.source.length; // Add HTML content length } // Safely access text content length if (delivery && delivery.content && delivery.content.text && delivery.content.text.source) { sizeInBytes += delivery.content.text.source.length; // Add text content length } // Log size for debugging logInfo("Delivery size log: Email size (" + (sizeInBytes / 1024).toFixed(2) + " KB)"); // Check if size exceeds limit if (sizeInBytes > maxSizeInBytes) { logWarning("Delivery aborted: Email size (" + (sizeInBytes / 1024).toFixed(2) + " KB) exceeds maximum allowed size of 35 KB."); return false; // Exclude the delivery } return true; // Allow the delivery

 


Let me know if this works.

Thanks

Sushant Trimukhe

Level 6
June 24, 2025

Hi @sushanttrimukhed  it worked ty. 

Just one question: why did you use this line: 

var sg = new StringGroup("nms:core");

It was a leftover from other script? I don't see the variable "sg" being used in other line... also... I commented the line and rule still worked. Ty