Reputation: 16553
I'm using the following Python code to send Mandrill email:
json_mandrill = dict(
key=MANDRILL_KEY,
template_name=template_name,
template_content=[],
global_merge_vars=[],
message=dict(to=[dict(email=recipient)])
)
for name, content in merge_vars.items():
json_mandrill["global_merge_vars"].append(
dict(name=name, content=content))
url = "https://mandrillapp.com/api/1.0/messages/send-template.json"
logging.info(json.dumps(json_mandrill))
result = urlfetch.fetch(url=url,
payload=json.dumps(json_mandrill),
method=urlfetch.POST,
headers={'Content-Type': 'application/x-www-form-urlencoded'})
Here is an example of the submitted JSON from my logs:
{"global_merge_vars": [{"content": 7, "name": "free_duration"}, {"content": 4615291308867584, "name": "eid"}, {"content": "poll", "name": "mode"}, {"content": "31 July 2015 at 09:44 EDT", "name": "exp"}, {"content": "Jeff", "name": "name"}],
"template_content": [],
"message": {"to": [{"email": REDACTED}]},
"key": REDACTED,
"template_name": "manager-welcome"}
My Mandrill settings are set to use Handlebars and here is an excerpt from the template:
<p>Dear {{name}},</p>
And this is what appears in the received email:
<p>Dear ,</p>
The emails get sent, but the merge variables in the email are just blank. Any idea what I am doing wrong?
Upvotes: 0
Views: 851
Reputation: 709
Looking at the submitted JSON, it looks like the "global_merge_vars" aren't nested properly. They should be nested in the "message" struct, instead of on the same level.
Upvotes: 2