Token replacement for MultiPart in MailService

Hi Everyone,

I have just started using the MailService plugin for a project we are
doing. It's an excellent component. One part I like, in particular,
is the Token replacement.

However, the Token replacement only appears to work with the standard
setBody and not against any body in a multi-part.

Firstly, if anyone has already resolved this, I'd like to know.

Otherwise.... I will look at implementing it.


Hi Gary, you can update it and then comitt the patch to the list so we can apply it to the main trunk or just post your updates here.


Luis F. Majano
Ortus Solutions, Corp

ColdBox Platform:
Linked In:
IECFUG Manager:


Here is my updated parseTokens method (just the body code - the method
signature has not changed). My brace coding style is not quite the
same as the Coldbox code base - but that can be resolved by whoever
moves it into the trunk. Essentially, the code checks to see if there
are mailParts and then treats them accordingly. The previous code for
a non-multipart message remains as the primary path. I have tested
this with two parts (HTML and TEXT).

  var tokens = arguments.Mail.getBodyTokens();
  var body = arguments.Mail.getBody();
  var mailParts = arguments.Mail.getMailParts();
  var key = 0;
  var mailPart = 0;

    for(key in tokens)
      body = replaceNoCase(body,"@#key#@", tokens[key],"all");
      body = mailParts[mailPart].body;
      for(key in tokens)
        body = replaceNoCase(body,"@#key#@", tokens[key],"all");
      mailParts[mailPart].body = body;