Skip to main content
sharma_nik
Level 2
Feb 19, 2025 11:58 AM UTC
Solved

Update SMTP header for multiple deliveries with a workflow

Hello

 

I am trying to update/insert SMTP header value in multiple deliveries. Lets say I have total 500 deliveries and out of those, I want to update SMTP header value for 300 deliveries using a workflow at once.

Is there any possibility to do this with a workflow? Or what is the easiest and faster way to do that?

 

 

Thanks in advance...!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SoufianeN
SoufianeNAccepted solution
Feb 20, 2025 3:11 PM UTC

Hello @sharma_nik ,

 

Here's a code you can use

// Define the new header content to be applied var newHeaderValue = "List-Unsubscribe: <Test>"; // Define a query to select the deliveries you want to update var queryDef = <queryDef schema="nms:delivery" operation="select"> <select> <node expr="@id" alias="deliveryID"/> </select> <where> <condition expr="@id IN (843982145, 844099895,844084604)"/>// Your Condition </where> </queryDef>; // Execute the query var deliveries = xtk.queryDef.create(queryDef).ExecuteQuery(); for each (var delivery in deliveries) { try { var deliveryId = delivery.deliveryID; // Load the delivery var deliveryObject = nms.delivery.load(deliveryId); if (deliveryObject) { //Set The SMTP Header deliveryObject.mailParameters.headers = newHeaderValue; // Save the changes deliveryObject.save(); logInfo("Successfully updated headers for delivery ID: " + deliveryId); } else { logWarning("Could not load delivery ID: " + deliveryId); } } catch (error) { logError("Error processing delivery ID " + deliveryId + ": " + error.message); } }

Regards,

3 replies

ParthaSarathy
Community Advisor
Community Advisor
Feb 20, 2025 6:28 AM UTC

Hi @sharma_nik ,

Write a JavaScript in the workflow to fetch all your 300 deliveries using queryDef and update the SMTP values in following fields,

[mailParameters/bounceAddress]
[mailParameters/errorAddress]
[mailParameters/headers]

Translate
~  ParthaSarathy S
SoufianeN
SoufianeNAccepted solution
Feb 20, 2025 3:11 PM UTC

Hello @sharma_nik ,

 

Here's a code you can use

// Define the new header content to be applied var newHeaderValue = "List-Unsubscribe: <Test>"; // Define a query to select the deliveries you want to update var queryDef = <queryDef schema="nms:delivery" operation="select"> <select> <node expr="@id" alias="deliveryID"/> </select> <where> <condition expr="@id IN (843982145, 844099895,844084604)"/>// Your Condition </where> </queryDef>; // Execute the query var deliveries = xtk.queryDef.create(queryDef).ExecuteQuery(); for each (var delivery in deliveries) { try { var deliveryId = delivery.deliveryID; // Load the delivery var deliveryObject = nms.delivery.load(deliveryId); if (deliveryObject) { //Set The SMTP Header deliveryObject.mailParameters.headers = newHeaderValue; // Save the changes deliveryObject.save(); logInfo("Successfully updated headers for delivery ID: " + deliveryId); } else { logWarning("Could not load delivery ID: " + deliveryId); } } catch (error) { logError("Error processing delivery ID " + deliveryId + ": " + error.message); } }

Regards,

Translate
Sukrity_Wadhwa
Level 4
Mar 4, 2025 8:20 AM UTC

Hi @sharma_nik,

Were you able to resolve this query with the help of the provided solutions, or do you still need further assistance? Please let us know. If any of the answers were helpful in moving you closer to a resolution, even partially, we encourage you to mark the one that helped the most as the 'Correct Reply.'
Thank you!

Translate
Sukrity Wadhwa