rschreijer / lutung

Lutung - A Java Mandrill API Connector
179 stars 119 forks source link

Template rendering returns plain template #65

Closed nightowlengineer closed 3 years ago

nightowlengineer commented 8 years ago

I think this is more a Mandrill issue than a library one (since I had a similar issue with a PHP library), however, it would be good to get some insight into what I could potentially be doing wrong.

Sending with a template works as expected, and the handlebar variables are replaced correctly. When asking for a rendered template, however, the API returns the correct template, but with no variables replaced.

Here's my implementation (ignore the verboseness of some components, this is still very much in development!)

public String sendEmail(MemberDO member) throws MandrillApiError, IOException
{
    final MergeVar[] mergeValues = { new MergeVar("member_first_name", member.getFirstName()),
            new MergeVar("member_grade", member.getType().toString()), new MergeVar("member_number", member.getMembershipNumber()),
            new MergeVar("initial_password", "still in development"),
            new MergeVar("sponsor_info", member.getType().equals(MemberType.SPONSOR)) };

    final Map<String, String> templateContent = new HashMap<String, String>();
    for (MergeVar value : mergeValues)
    {
        templateContent.put(value.getName(), value.getContent().toString());
    }

    final String emailTo = member.getEmail();

    final MergeVarBucket mergeBucket = new MergeVarBucket();
    mergeBucket.setRcpt(emailTo);
    mergeBucket.setVars(mergeValues);

    final List<MergeVarBucket> mergeBuckets = new ArrayList<MergeVarBucket>();
    mergeBuckets.add(mergeBucket);

    final Recipient recipient = new Recipient();
    recipient.setEmail(emailTo);

    final List<Recipient> recipients = new ArrayList<Recipient>();
    recipients.add(recipient);

    final MandrillMessage message = new MandrillMessage();
    message.setTo(recipients);
    message.setMergeLanguage("handlebars");
    message.setMergeVars(mergeBuckets);

    final String render = mandrill.templates().render("welcome", templateContent, templateContent);
    final MandrillMessageStatus[] deliveries = mandrill.messages().sendTemplate("welcome", templateContent, message, false);
    return null; // render or delivery status
}
billoneil commented 8 years ago

It doesn't look like the Templates.render API allows you to pass the merge_language. I think that could be causing the issue? https://mandrillapp.com/api/docs/templates.JSON.html#method=render

nightowlengineer commented 8 years ago

Quite possibly. I've managed to find a contact form for Mailchimp and have emailed them (Ticket# LTK1218902329770X). Will see what I hear back.

nightowlengineer commented 8 years ago

Had a response earlier:

Thanks for getting back to us. Unfortunately, you're correct - the templates/render API call does not currently support Handlebars templates. While I can't provide an exact ETA for when the render API call will work with Handlebars, this is something that our developers are planning to extend support for.

I would suggesting keeping an eye on our API Docs as that support will be noted there as an additional parameter for the call as soon as it is supported.

Probably keep this issue open till it's made live, and see if there's any additional implementation to be made in the library to support it?

billoneil commented 8 years ago

I assume they will just add an extra parameter to the API for this. It should be simple once they implement it. We can keep this issue open for now.

nightowlengineer commented 8 years ago

Just a small further update from Mandrill:

Our current development cycle means that the earliest you may expect for this update would be Q2 of next year.

billoneil commented 8 years ago

If this is blocking you it wouldn't be very difficult to implement on your own without the Mandrill API. Just find one of the Handlebars template libraries for java, pass in the template and the data and you can render it yourself.

stpriyanka commented 7 years ago

I had the same issue last week. I solved it using handlebars.net library. I have shared the example. https://stpriyanka.wordpress.com/mandrill-template-rendering-using-handlebar/ . Hope this will help others.

gregblass commented 6 years ago

@billoneil You assumed wrong. Still not done.

billoneil commented 6 years ago

@gregblass I believe my assumption was correct they just still haven't prioritized it. There are a few easy workarounds you can do client side or you can ping their support team again but it doesn't sound like their highest priority.

bikalbasnet commented 5 years ago

I guess this is till not on the priority after 4 years?

gregblass commented 5 years ago

Mandril seems like a failed attempt that they kept alive. I wouldn’t expect this to happen, like...ever. Their support is email only, takes days, etc.

To be fair, MailChimp actually is pretty great, and their API V3 is too (especially compared to constant contact). Mandrill probably just wasn’t very profitable.

cpu-meltdown commented 5 years ago

Well, I should've looked here before implementing it 😅 @billoneil Any suggestions on how to include recipient specific info using lutung?

nategasser commented 3 years ago

Fall of 2021 checking in here. Still doesn't work, 7 years later.

Frustrating when companies don't prioritize supporting developers.

rschreijer commented 3 years ago

@nategasser FYI, your comment does not reach the mailchimp team this way. This is NOT an official mandrill project and this project is NOT maintained by mailchimp. This project is actually not being maintained at all anymore.