Params cannot take complex objects
Closed this issue · 1 comments
Following the guide for using control tags in email templates here we need to be able to submit more than String value pairs to params on SendSmtpEmail
Eg I need to list out products I'd use a template like;
Dear {{params.NAME}}
Thanks for the order, here is your invoice;
{% for item in params.ITEMS %}
{{item.name}} - {{item.amount}} - {{item.price}}
{% endfor %}
And use this api as;
List<Item> items = new ArrayList<>();
items.add(new Item("Cogs", "2", "$40"));
items.add(new Item("Spanners", "6", "$2));
Map<String, Object> params = new HashMap<>();
params .put("name", "Joe's Hardware");
params .put("items", items);
SmtpApi api = new SmtpApi();
SendSmtpEmail email = new SendSmtpEmail();
email.addToItem(new SendSmtpEmailTo().email(to));
email.templateId(templateId);
email.params(params ); <------- compilation error, params only takes Map<String, String> !!!
api.sendTransacEmail(email);
Unfortunately as pointed out params
only takes a Map<String, String> which makes it impossible to send in deeper lists for iteration etc. Is there another approach that is better suited? For now I have forked this repo and changed the Map to <String, Object> and it solved my issue but I'm not sure if it would create more issues in other uses of the API.
Hi @nickfoote, please try the latest release, you can refer the example mentioned here.
Properties params = new Properties();
params.setProperty("parameter", "My param value");
params.setProperty("subject", "New Subject");
Thanks