ACC - Listheader unsubscribe | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Manoj_Kumar

Hello @jkkkkkkkkkkkkkkkkk 

 

I believe you are trying to use the typology rule to automatically add a list-unsubscribe header to the deliveries.

 

You can use this code to do that:

function addHeader(headers, header, value) { var headerLine = header + ": " + value; var regExp = new RegExp(header + ":(.*)$", "i") var headerLines = headers.split("\n"); for (var i=0; i < headerLines.length; i++) { var match = headerLines[i].match(regExp) if ( match != null ) { // replace the existing header line headerLines[i] = headerLine; return headerLines.join("\n"); } } // add a new header line headerLines.push(headerLine); return headerLines.join("\n"); } function getHeader(headers, header) { var regExp = new RegExp(header + ":(.*)$", "i") var headerLines = headers.split("\n"); for each (line in headerLines) { var match = line.match(regExp) if ( match != null ) { return match[1].replace(/^\s*/, ""); } } return ""; } var header = getHeader(delivery.mailParameters.headers, "List-Unsubscribe"); if ( header == "" ) { // List-Unsubscribe header needs to be added delivery.mailParameters.headers = addHeader(delivery.mailParameters.headers, "List-Unsubscribe", "<mailto:<%@ include option='NmsEmail_DefaultErrorAddr' %>?subject=unsubscribe<%= escape(message.mimeMessageId) %>>"); } else if ( header.match(/message\.mimeMessageId/) == null ) { // message ID need to be added for gmail header = header.replace(/subject=unsubscribe/, "subject=unsubscribe<%= escape(message.mimeMessageId) %>") delivery.mailParameters.headers = addHeader(delivery.mailParameters.headers, "List-Unsubscribe", header); }

 

 

3 replies

Marcel_Szimonisz
Community Advisor
Community Advisor
December 6, 2023

Hello @jkkkkkkkkkkkkkkkkk ,

what you mean by listheader unsubscribe on typology rule? It is not clear at all. What I understand is to create warning if the template does not contain list-unsubscribe header?

 

If that so in typology rules you have entire delivery object at hand and you can to check the headers of the message with eg regular expression

 

 

Marcel

Manoj_Kumar
Community Advisor
Manoj_KumarCommunity AdvisorAccepted solution
Community Advisor
December 6, 2023

Hello @jkkkkkkkkkkkkkkkkk 

 

I believe you are trying to use the typology rule to automatically add a list-unsubscribe header to the deliveries.

 

You can use this code to do that:

function addHeader(headers, header, value) { var headerLine = header + ": " + value; var regExp = new RegExp(header + ":(.*)$", "i") var headerLines = headers.split("\n"); for (var i=0; i < headerLines.length; i++) { var match = headerLines[i].match(regExp) if ( match != null ) { // replace the existing header line headerLines[i] = headerLine; return headerLines.join("\n"); } } // add a new header line headerLines.push(headerLine); return headerLines.join("\n"); } function getHeader(headers, header) { var regExp = new RegExp(header + ":(.*)$", "i") var headerLines = headers.split("\n"); for each (line in headerLines) { var match = line.match(regExp) if ( match != null ) { return match[1].replace(/^\s*/, ""); } } return ""; } var header = getHeader(delivery.mailParameters.headers, "List-Unsubscribe"); if ( header == "" ) { // List-Unsubscribe header needs to be added delivery.mailParameters.headers = addHeader(delivery.mailParameters.headers, "List-Unsubscribe", "<mailto:<%@ include option='NmsEmail_DefaultErrorAddr' %>?subject=unsubscribe<%= escape(message.mimeMessageId) %>>"); } else if ( header.match(/message\.mimeMessageId/) == null ) { // message ID need to be added for gmail header = header.replace(/subject=unsubscribe/, "subject=unsubscribe<%= escape(message.mimeMessageId) %>") delivery.mailParameters.headers = addHeader(delivery.mailParameters.headers, "List-Unsubscribe", header); }

 

 

Manoj     Find me on LinkedIn
Level 3
April 24, 2024

@_manoj_kumar_ This code works perfectly for audiences of Recipient table. But what are the tweaks required for this code to work on table other than recipient(different target mapping).

rahulkad29786
Level 4
April 24, 2024

Hi @ratika ,

Since the code by default updates the nms:recipient table, so for any custom table to get updated, you need to tweak the script code in the noClick Unsub Webapp, which has the defined Unsubscription function and there you need to provide context to your custom table.

Hope that helps.

 

Sukrity_Wadhwa
Community Manager
Community Manager
December 15, 2023

Hi @jkkkkkkkkkkkkkkkkk,

Were you able to resolve this query with the help of the given solutions or do you still need more help here? Do let us know. In case the given solutions were helpful, then kindly choose the one that helped you the most as the 'Correct Reply'.
Thanks!

Sukrity Wadhwa