Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Velocity Script

When creating a Script you may need to use a specific method that will perform specific actions. These methods can be found by expanding the Velocity Context section. Here you will see some pages that contain methods that you may need to use. When you expand the Velocity Context you will also find links to Javadoc for the published Java classes to help guide you.

...

Script examples

Adding

...

your mailbox email address

...

Script:

Code Block
$taskUtils.getHeaderOrCreate($message, 'To').addValue('add.me.as.email.user@mycompany.com')

...

Code Block
$assert.assertEquals('Fernando <fernando@mail.com>,add.me.as.email.user@mycompany.com', $taskUtils.getHeader($message, 'To').getValueAsCSV())

Removing the Date header

Script:

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

...

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

Detecting a missing From address and adding it to the email

Script:

Code Block
#set ($original = $message.getFrom()[0].getAddress().toLowerCase()) ##Extracts the Value found within the From header
#if ($stringUtils.isEmpty($original))  ##Checks if From address is missing
    $message.setFrom("newaddress@example.com") ##Sets the From address
#end

...

Code Block
$assert.assertEquals('newaddress@example.com', $taskUtils.getHeader($message, 'from').getValueAsCSV())

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.

...