JS PreProc Task: Replace From: address
Replacing the From address
This example shows how to manipulate the From address, to detect one domain and swap it out for another.
Script:
var original = message.getHeader('from').toLowerCase(); //Extracts the Value found within the From header
if (original.endsWith('@thepluginpeople.com')) { //Checks if sender address is a specific address
var name = original.split('@')[0];
message.setHeader('from',name + '@replaced.com'); //Changes original from address to be the extracted name and email address
}
Example Email:
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@thepluginpeople.com
To: test@example.com
Content-Type: text/plain; charset=UTF-8
CHANGE BODY!!!
Test Script:
assert.equal(message.getHeader('from'), 'ryan@replaced.com', 'Example message');
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.