Table of Contents |
---|
Available Script Context
Info |
---|
|
API | Notes |
---|---|
| Get all headers of a message. |
| Get value of a message header Parameters
|
| Set the value of a message header Parameters
|
| Adds output that is recorded during execution and shown in the processing report. Parameters
|
| Set the processing outcome of the script Parameters
|
| See below. https://nodejs.org/api/assert.html |
| Regular expressions can be evaluated within the script. This is often used for searches within string values for matching content. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp for more information. |
Assertions
See https://nodejs.org/api/assert.html for full Assert API documentation.
...
In the example email, the Subject is not the expected one, and therefore the following output will be produced:
...
Script examples
Adding an email address to your emails
Script:
Code Block |
---|
var to = message.getHeader('to'); var newTo = to + ', someone@example.com'; message.setHeader('to', newTo); |
...
Code Block |
---|
assert.equal(message.getHeader('to'), 'test@example.com, someone@example.com', 'Example message'); |
Detecting a missing From address and adding it to the email
Script:
Code Block |
---|
var from = message.getHeader('from'); //Extracts the Value found within the From header if (from == null) { //Checks if From address is missing message.setHeader('from', 'newaddress@example.com'); //Sets the From address } |
...
Code Block |
---|
assert.equal(message.getHeader('from'), 'newaddress@example.com', 'Example message'); |
Replacing the From address
This example shows how to manipulate the From address, to detect one domain and swap it out for another.
...
Here you can see the example mail processing report generated by JEMHC for our support project. A user would have been associated if it didn’t exist, in this case we’ve simply created a new portal user.
...
Extracting an address from the name part and setting it as the From address
If you are receiving emails that are sent from a system address with a personal part that contains the actual sender address, the script below will extract the actual sender address from the original personal part and will set this value as the sender of the email, so that it can be processed correctly.
...
Here you can see the example mail processing report generated by JEMHC for this Test Case. A user would have been associated if it didn’t exist, in this case we’ve simply created a new portal user with the correct email address and name.
...
Using Regex to extract a specific value from the subject and set as a new header value
If you want to retrieve specific text from the email subject then you can do so by searching the email subject with a Regular Expression that will extract the matching values. The below example will search the email subject for specific content and if found it will then set the value to the relevant email header.
...