Expand my Community achievements bar.

SOLVED

Update SMTP header for multiple deliveries with a workflow

Avatar

Level 2

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...!

Topics

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

1 Accepted Solution

Avatar

Correct answer by
Level 1

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,

View solution in original post

3 Replies

Avatar

Community Advisor

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]

Avatar

Correct answer by
Level 1

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,

Avatar

Administrator

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!



Sukrity Wadhwa