JS PreProc Task: Extract address from name part and set as address
JS PreProc Task: Extract address from name part and set as address
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.
Example Script:
var original = message.getHeader('from').toString(); //Extracts the Value found within the From header
if (original.includes('system@external.com')) { //Checks if sender address is a specific address
var address = original.substring(original.indexOf('(') + 1, original.indexOf(')')).trim(); //Extracts the address from between the two brackets "("")"
var personal = original.substring(original.indexOf('"') + 1, original.indexOf('(')).trim(); //Extracts the real senders personal part (Name)
message.setHeader("from", '"' + personal + '" ' + '<' + address + '>'); //Changes original from address to be the extracted name and email address
}
Example Test Case:
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:
assert.equal(message.getHeader("from"), '"ryan example" <ryan@example.com>', 'Example message');
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 with the correct email address and name.
, multiple selections available,