JS PreProc Task: Add additional recipient

Adding an email address to your emails

Script:

var to = message.getHeader('to'); var newTo = to + ', someone@example.com'; message.setHeader('to', newTo);

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: andy@thepluginpeople.com To: test@example.com Content-Type: text/plain; charset=UTF-8 CHANGE BODY!!!

Test Script:

You can assert the test case after it is processed by your script, by using the following assert. You should see that the email will have two “to” addresses, the original email address and the one the script adds.

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:

Test Script:

The following assert will check that the From address is now set correctly.