5
votes

Is it possible to use nested merge tags?

What we need is to be able to define the UNSUB tag depending on the values from other merge tags, like on this example:

<a 
href="*|UNSUB:*|COMMUNITYURL|*/site/unsuscribe/user_id/*|USERID|*/hash/*|HASH|*/type/all|*">
Unsubscribe
</a>

Is this correct? Should be done in a different way?

3
(I haven't worked with the mandrill API). It's not clear in your question why you want to define the UNSUB tag. What stops you from doing this directly: <a href="*|COMMUNITYURL|*/site/unsuscribe/user_id/*|USERID|*/hash/*|HASH|*/type/all|*"> Unsubscribe </a> ? - Tomás
Because in Mandrill, when you add the UNSUB merge tag, it automatically adds the List-Unsubscribe header to the message. And your mailing reputation is improved :) - AntonioHS
By the way, I'm sending the email through the api using sendTemplate, and it's one single request for several mails. I know of the existence of the headers section in the expected json, but that's a general section, and I need a personalized unsubscribe link for every mail. So I would need another section for personalized headers, like for the merge vars you can use the global_merge_vars section for merge tags that are the same in all emails and the merge_vars section for merge tags that are dependent of the particular mail being sent. - AntonioHS

3 Answers

2
votes

It's not currently possible to nest merge tags. In this case, your best bet would be to add your own List-Unsubscribe headers (using the headers parameter in the API) and pass either your own URL, or a URL constructed with your merge tags but not the UNSUB merge tag.

2
votes

From the API:

What happens when the [unsubscribe] link is clicked?

If a recipient clicks the generated link, the message status is changed to Unsubscribed and > the recipient's address is added to the Rejection Blacklist in your Mandrill account. The redirect URL will be appended to include two querystring parameters that can be used for processing the unsubscribe in your own system or database:
md_id - the _id, as provided in the API call and webhooks of the specific message where the unsubscribe link was clicked
md_email - a URL-encoded version of the recipient's email address

So you don't have to worry about generating an unsubscribe url for every user. Just put a generic url and mandrill automatically will append to you the email of that user in the md_email variable.

The documentation suggest that you do this then:

<a href="*|UNSUB:http://mywebsite.com/unsub|*">Click here to unsubscribe.</a>

And mandrill will append the correct user email and id:

 http://mywebsite.com/[email protected]&m_id=23321
0
votes

Since mandrill doesn't support nested merge tags, here is the solution for the case like yours if you dont mind after user click unsub, it did't go to mandrill's black list, since the unsubsription are all handled by your app.

PER YOUR CASE:

  1. Manually compose your unsubscribe link e.g. *|COMMUNITYURL|*/site/unsuscribe/user_id/*|USERID|*/hash/*|HASH|*/type/all/
  2. At the end of your link, append the mandrill recipient email var.email=*|EMAIL|* e.g. *|COMMUNITYURL|*/site/unsuscribe/user_id/*|USERID|*/hash/*|HASH|*/type/all/?email=*|EMAIL|*
  3. Put the link to your mandrill template

    <a href="*|COMMUNITYURL|*/site/unsuscribe/user_id/*|USERID|*/hash/*|HASH|*/type/all/?email=*|EMAIL|*">Unsubscribe Me</a>

reference: mandrill doc