Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

If you want to manipulate email message headers, this can be done through coded Pre-Processing tasks. Most tasks will fix a particular problem.


Table of Contents


Step-by-step guide

  1. Enable pre-processing tasks by going to Profiles-> Cog icon > Edit and check Use PreProcessed Message

    Image RemovedImage Added

  2. Select the the tasks you want to enable.

Scripted Task Configuration

The Scripted Task allows you to change message with a Velocity script. 

The objective of the scripted task is to modify the message before running the standard JEMHCloud process using a programmatic script. Even though Velocity is a template language designed to render UI, Emails, etc. it can be used to modify objects problematically including objects problematically including the message. Velocity is the language selected to allow users customize email templates and this is another way to be used. Other  Other tasks are to fix most common problems in received messages.

After enabling the task you will be able to write your own script. This tutorial will show several examples on how to modify a message. Please note this is an advance feature and minimal programming skill are necessary (you may learn here!). Some examples:

Code Block
Code Block
$taskUtils.getHeader($message, 'Change-Me-If-I-Am-In-The-Message').setValue('new value') // header is changed if it exists
$taskUtils.getHeaderOrCreate($message, 'Change-Or-Create-Me').setValue('new value') // header is changed or created replacing existing value
$taskUtils.getHeaderOrCreate($message, 'Update-Me').addValue('Add This Value') // header is changed or created adding a new value to existing value
$taskUtils.getHeader($message, 'Remove-Me').remove() // headers is removed
$taskUtils.getHeader($message, 'Remove-Me-Too').setValue(null) // headers is removed
$taskUtils.getHeader($message, 'Remove-Me').setValue('  ') // headers is removed
$taskUtils.getHeader($message, 'CC').remove() // Removes CC
$taskUtils.getHeaderOrCreate($message, 'To').addValue('') // Adds an email user to all the issues created/updated by email.
//A way to fix the encoding problem, replacing the problematic encoding (ISO-8859-8-x) in all the Content-Type headers in all mime parts to UTF-8 (Content Type Mapper Task is the recommended way to fix this problem)
#foreach ($header in $taskUtils.getHeaders($message, 'Content-Type', true)) // Second parameters defines which headers to be loaded. True means include sub-parts.


For example, if you're adding a email address to your emails

Code Block
$taskUtils.getHeaderOrCreate($message, 'To').addValue('')

You can assert that the test case after being processed will have the new address in the To: header.

Code Block
$assert.assertEquals('Fernando <>,', $taskUtils.getHeader($message, 'To').getValueAsCSV())

The processed email will have two to: addresses, the original email address and the one the script adds

If you remove the Date header:

Code Block
$taskUtils.getHeader($message, 'Date).remove()

The header must be null

Code Block
$assert.assertNull($taskUtils.getHeader($message, 'Date'))

The test case can be created from scratch or based on one of your normal test cases.


You can test your script pressing the validate button or when you submit the profile configuration. A profile with failing assertions cannot be saved. It's highly recommended to test your script adding many assertions to verify it works properly. If an assertion fails, the error below the script editor will show you the line and column number in the script that is failing.A failed assertionImage Removed


Content Type Mapper Configuration

Sometimes, email clients refer to the encoding of content within the email in such a way as to make it unprocessable by JEMHC /Javamail.  Sometimes, it is because an illegal value is presented in the email, for example 7-bit which is not legal but 7bit is (see Oracle page referring RFC-2045 supported types).  JEMHC can fix problems like this but they need to be configured:


Notes about email headers:

1) One header may have multiple values

Code Block
To: "John Doe" <>
Code Block
To: "Dave Doe" <>

aHeader.getValues() returns a list of String values, potentially including double quotes: [ "John Doe" <>, "Dave Doe" <> ]

 aHeader aHeader.getValueAsCSV() joins all the values together returning a simple String value, potentially including double quotes: "John Doe" <>,"Dave Doe" <>


In our example, $taskUtils.getHeaders($message, 'Content-Type', true) returns the list of all Content-Type headers any part level.

Content by Label


cqllabel = "kb-how-to-article" and type = "page" and space = "JEMHC"
Page Properties

Related issues