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

Sukrity_Wadhwa
Employee
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
_Manoj_Kumar_
_Manoj_Kumar_Accepted solution
New Participant
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
New Participant
January 22, 2024

I am receiving an error saying the typology rule "List Unsubscribe" has detected a problem. Do we need to change anything in the code?

_Manoj_Kumar_
New Participant
January 23, 2024

@swaroopgowtham  Do you see the header added in the email? If yes, then you can ignore the warning.

     Manoj     Find me on LinkedIn
Marcel_Szimonisz
New Participant
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