Setting Custom Email Headers

pranavparmar
Giga Contributor

We are working towards managing ServiceNow outbound emails as Conversation using thread index & thread topic. Did anyone try this before?

We want to append thread topic & thread index headers whenever we sent notification from ServiceNow. This will help users to manage related emails for same incident, problem, change or any task emails from servicenow.

Anyhelp would be appreciated.

Thanks

Pranav

6 REPLIES 6

lss123
Tera Contributor

I tried this today and succeeded.   I created a business rule on the sys_email table ("on before", "insert/update") to add the headers.   The script is below.   It is important to put your headers BEFORE theirs.   If you simply append your headers, they will be cut off.



/* add headers */


if(current.headers.indexOf("X-My-Header-Here") < 0){


  current.headers = "X-My-Header-Here: " + headerValue + "\n" + current.headers;


}


steph3
Tera Contributor

Hi Louis, does this continue to work for you? I am seeing elsewhere in the community where it says that headers cannot be access/changed via business rules. I am trying to replace a header (X-ServiceNow-Generated) and in the record in sys_email it looks like it works but when the email arrives it still has the header.



Thanks!


lss123
Tera Contributor

Yeah, we're on Istanbul and it still works.   Adding headers in there stands a better chance of removing headers, I think.   I'm not sure how it works under the hood, but when I tried to append our custom headers after ServiceNow's, they ended up disappearing before the actual email was sent.   So at some point, headers are re-evaluated and reprocessed after the business rule but before leaving the system.   What I described above was my workaround to get around that.



I'd bet that if you are removing headers in the business rule, whatever reprocessing happens after that is putting them back.   Out of curiosity, what headers are you trying to remove?   I believe some can be controlled by system properties.


steph3
Tera Contributor

Thanks for your response! I am trying to remove the X-ServiceNow-Generated:true header which prevents ServiceNow from ingesting emails from other instances.I don't want to remove it all together, just for emails that are going to certain recipients which I have specified in the business rule.



Thanks again!