Question

I am using the Mandrill API and have a simple template:

<html>
    <body>
        <p>Hello *|name|* 
        </p>
    </body>
</html>

And am using the send-template.json API from here: https://mandrillapp.com/api/docs/messages.JSON.html#method=send-template

And when i insert my payload then the 'name' var is still not populated, any idea why?

{
    "key": "secret",
    "template_name": "mandrill-sunday",
    "template_content": [
        {
            "name": "example name"
        }
    ],
    "message": {
        "html": "<p>Example HTML content</p>",
        "text": "Example text content",
        "subject": "example subject",
        "from_email": "message.from_email@example.com",
        "from_name": "Example Name",
        "to": [
            {
                "email": "myemail@gmail.com",
                "name": "Recipient Name"
            }
        ],
        "headers": {
            "Reply-To": "myemail@yahoo.com"
        },
        "important": false,
        "track_opens": null,
        "track_clicks": null,
        "auto_text": null,
        "auto_html": null,
        "inline_css": null,
        "url_strip_qs": null,
        "preserve_recipients": null,
        "bcc_address": "kamil@myemail.com",
        "tracking_domain": null,
        "signing_domain": null,
        "merge": true,
        "global_merge_vars": [
            {
                "name": "merge1"
            }
        ],
        "merge_vars": [
            {
                "rcpt": "myemail@gmail.com",
                "vars": [
                    {
                        "name": "merge2"
                    }
                ]
            }
        ],
        "tags": [
            "password-resets"
        ],
        "google_analytics_domains": [
            "mydomain.com"
        ],
        "google_analytics_campaign": "mandrill-sunday",
        "metadata": {
            "website": "www.mydomain.com"
        },
        "recipient_metadata": [
            {
                "rcpt": "myemail@gmail.com",
                "values": {
                    "user_id": 123456
                }
            }
        ]
    },
    "async": false
}

But the only thing i get back in my email sent is:

Hello *|name|*
Was it helpful?

Solution

Because each replacement requires two fields: its name and its contents. So your merge should become something like:

"vars": [
  {
     "name": "name",
     "content" : "merge2"
  }
]

OTHER TIPS

Have to use global_merge_vars

global_merge_vars': [{'content': 'merge1 content', 'name': 'name'}]

There's two things that could trip you up here.

1) (as others have mentioned) Each merge variable object has two key-value pairs, name and content:

'global_merge_vars': [
            {
                'name': 'fullName',
                'content': 'foo bar',
            },
            {
                'name': 'email',
                'content': 'foobar@gmail.com',
            }

 ],

2) Make sure to set your merge language to either mailchimp or handlebars for mandrill.

'merge_language': 'mailchimp',

Source: https://mandrillapp.com/api/docs/messages.python.html#method=send-template

I just tried accepted answer with SMTP header and it did not work. (I'm writing in Ruby (on Rails) here)

headers['X-MC-MergeVars'] = [
  {name: 'name', content: 'pieter'}
].to_json

Though most straightforward way works. Maybe they changed something or SMTP headers works differently?.. This works:

headers['X-MC-MergeVars'] = {
  name: 'pieter'
}.to_json
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top