...
This example shows how to manipulate the From: address, to detect one domain and swap it out for another.
Script
Code Block |
---|
#set ($original = $message.getFrom()[0].getAddress().toLowerCase()) ##Extracts the Value found within the From header #if ($original.endsWith("@thepluginpeople.com")) ##checks if sender address is a specific address #set ($name = $original.split("@")[0]) $message.setFrom($name + "@replaced.com") ##Changes original from address to be the extracted name and email address #end |
Example Email
Code Block |
---|
MIME-Version: 1.0 Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT) Date: Sun, 19 Jun 2011 17:42:26 +1200 Subject: CHANGE_SUBJECT!!! From: andy@thepluginpeople.com To: test@example.com Content-Type: text/plain; charset=UTF-8 CHANGE BODY!!! |
Test script
Code Block |
---|
$assert.assertTrue($message.getFrom()[0].getAddress().equalsIgnoreCase("andy@replaced.com")) |
Yes, it would be handy to show ‘debug’ render output where #if #else are used ,
Jira Legacy | ||||||
---|---|---|---|---|---|---|
|
Proof
...
Processing Report
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:
...
Extract address from name part of sender address
If you are receiving emails that contain a system address with the personal part containing the actual sender address then you can use the following address to extract and set this value from the name part as the sender.
Example Script:
Code Block |
---|
#set ($original = $taskUtils.getHeaderValue($message, "from").toString()) ##Extracts the Value found within the From header
#if ($original.contains("system@external.com")) ##checks if sender address is a specific address
#set ($address = $stringUtils.substringBetween($original, "(", ")")) ##Extracts the address from between the two brackets "("")"
#set ($personal = $stringUtils.substringBetween($original, '"', "(")) ##Extracts the real senders personal part (Name)
$message.setFrom('"' + $personal + '"' + "<"+ $address +">") ##Changes original from address to be the extracted name and email address
#end |
Example Test Case:
Code Block |
---|
MIME-Version: 1.0
Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT)
Date: Sun, 19 Jun 2011 17:42:26 +1200
Subject: CHANGE_SUBJECT!!!
From: "ryan example (ryan@example.com)" <system@external.com>
To: test@test.com
Content-Type: text/plain; charset=UTF-8
CHANGE BODY!!! |
Test Script:
Code Block |
---|
$assert.assertTrue($message.getFrom()[0].getAddress().equalsIgnoreCase("user@example.com")) |
Proof:
...
Processing Report:
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:
...
Related articles
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...