[coldbox-3.8] MailService BodyTokens


In MailService we are able to set body token and use these values on the view (content of email body). Currently the only values that can be set on the body tokens are simple, i.e. not array, structs, etc.
My question: Is it possible to assign a complex value to the body token, e.g. an array, struct, rc collection and use them on the view that render the email body content?

Here’s an example to illustrate:

In a handler method that handles the email send out:
stInfo = stReportInfo

In the view (for email body content):
loop through @stInfo@??

I know the answer is most likely ‘no’, but I want to check to see if it’s possible. Thanks.


You can do this, but not with the tokens. Create a view for the E-mail body and use renderView() to generate the view. Pass in the bits you need directly via view args so you don’t pollute you rc or prc. Then set the returned HTML directly into the E-mail.

Here you can see something similar going on in ContentBox CMS.




ColdBox/CommandBox Developer Advocate
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks Brad! Will try out your suggestion.

Thanks Brad!

Success! This is what I used:

In a handler method that gather the info and sends out the email (partial):

stInfo = {};
stInfo.firstname = “John”;
stInfo.lastname = “Doe”;
/* etc, etc…*/

mail.setBody( renderer.renderView( view=‘the email view file’, args= stInfo ));

Then in the email view file, i reference the local variables as: