This is just like my query post except it's from a bean. For those that aren't familiar with a bean, I use Coldbox as my MVC framework of choice which can then populate the bean. I have a toStruct function in my base Bean that I use. I posted it here also. So the concept is from to Bean to struct and then loop over it to dynamically populate a template. So this combined with my previous function I've turned my entire email model into two dynamic functions sending pretty emails on the fly.

    public string function sendElasticEmailFromBean(myBean)
        {
            LOCAL.httpService = new http();
            LOCAL.httpService.setMethod("post");
            LOCAL.httpService.setCharset("utf-8");
            LOCAL.httpService.setUrl(THIS.SENDURL);
            LOCAL.httpService.addParam(type="formfield",name="username",value=THIS.USERNAME);
            LOCAL.httpService.addParam(type="formfield",name="api_key",value=THIS.API_KEY);
            LOCAL.httpService.addParam(type="formfield",name="from",value=THIS.FROM);
            LOCAL.httpService.addParam(type="formfield",name="from_name",value=THIS.FROM_NAME);
            LOCAL.httpService.addParam(type="formfield",name="to",value=ARGUMENTS.myBean.getTo());
            LOCAL.httpService.addParam(type="formfield",name="subject",value=ARGUMENTS.myBean.getSubject());
            if (ARGUMENTS.myBean.getTemplate() neq '')
            {
                LOCAL.httpService.addParam(type="formfield",name="template",value=ARGUMENTS.myBean.getTemplate());
                LOCAL.httpService.addParam(type="formfield",name="merge_body",value=ARGUMENTS.myBean.getBody());
            }    
            else
                LOCAL.httpService.addParam(type="formfield",name="body_html",value=ARGUMENTS.myBean.getBody());    
            if (ARGUMENTS.myBean.getMergeName() neq '')
                LOCAL.httpService.addParam(type="formfield",name="data_source",value=ARGUMENTS.myBean.getMergeName());
            
            LOCAL.columns=StructKeyArray(ARGUMENTS.myBean.toStruct());
            for (local.i=1; LOCAL.i LTE arraylen(LOCAL.columns); LOCAL.i=LOCAL.i+1)
            {
                LOCAL.temp=evaluate("ARGUMENTS.myBean.get"& LOCAL.columns[i]&"()");
                if( isDefined('LOCAL.temp'))
                    LOCAL.httpService.addParam(type="formfield",name="merge_#LOCAL.columns[i]#",value="#LOCAL.temp#");
            }
            LOCAL.result = LOCAL.httpService.send().getPrefix();
            return LOCAL.result.filecontent;
        }

    public struct function toStruct()
    {
        LOCAL.rtn = structNew();
        for(LOCAL.x=1; LOCAL.x lte ArrayLen(getMetaData(THIS).properties); LOCAL.x = LOCAL.x + 1)
        {
            if(isDefined(getMetaData(THIS).properties[LOCAL.x].name)) value = evaluate(getMetaData(THIS).properties[x].name);
            else LOCAL.value = "";
            
            structInsert(LOCAL.rtn, getMetaData(THIS).properties[LOCAL.x].name, value);
        }
        return LOCAL.rtn;
    }