Expand my Community achievements bar.

SOLVED

Typologie rule code for Email size?

Avatar

Level 6

Hi,

How would you create a typology rule to rule out devlieries with a size greater than X (35K)?

According to docs, max size should be 35K. 

Delivery performances best practices | Adobe Campaign

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 4

@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

 

SushantTrimukheD_0-1750670933689.pngSushantTrimukheD_1-1750670966198.png


Let me know if this works.

Thanks

Sushant Trimukhe

View solution in original post

2 Replies

Avatar

Correct answer by
Level 4

@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

 

SushantTrimukheD_0-1750670933689.pngSushantTrimukheD_1-1750670966198.png


Let me know if this works.

Thanks

Sushant Trimukhe

Avatar

Level 6

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