Wylio / meteor-mandrill

Meteor package for sending email via Mandrill
https://atmospherejs.com/wylio/mandrill
32 stars 8 forks source link

Having some trouble getting merge vars working with this package #5

Closed rfines closed 9 years ago

rfines commented 9 years ago

I have been trying to send some simple template emails, and none of the merge vars are getting passed through to the template. Can you give me some guidance? I have my sendTemplate call set up like this:

sendTemplatedEmail: function(to, merge_vars, template_slug, template_content){
/*
  Sends an email using Mandrill and a Mandrill template.
  @Params:
    to: email of recipient
    merge_vars: array of key/value pairs to inject into email tmeplate
    template_slug: "vendorinvite" or "exhibitorinvite" or "outsideinvite"
    EXAMPLE:
    [
        {
            "rcpt": "email@example.com",
            "vars": [
                {
                    "name": "fname",
                    "content": "John"
                },
                {
                    "name": "lname",
                    "content": "Smith"
                }
            ]
        }
    ],

    template_content: array of objects to be injected into the template
    [
        {}
    ]

*/
console.log(to);
console.log(merge_vars[0].vars);
this.unblock();
var templName = template_slug || 'vendorinvite'
var globals = [];
return Meteor.Mandrill.sendTemplate({

          template_name: templName,
          template_content: template_content,
          message: {
              global_merge_vars: globals,
              merge_vars:merge_vars,
              to: [{"email": to}
              ]
          }
      });
}

with the merge_vars looking like this:

[ { name: 'exhibitorname', content: 'ExhibitMe' },
  { name: 'showname', content: 'Show Name' },
  { name: 'associationname', content: 'Anita Borg Institute for Women in Technology' },
  { name: 'emailmessage', content: 'asfa' },
  { name: 'invitelink',content:'http://localhost:3000/shows/mrj5xMKEohfkpCNkr/invites/nayuJfJBXCHGP58Bw' }
]

I have a pretty basic template set up in mandrill but when I send this email out, I get a bunch of merge var tags and not the desired content.

Here is an example of the merge tag definitions in the template:

You have been invited to *|showname|* by *|associationname|*.

Can you help me out??

danieljonce commented 9 years ago

Looks like maybe you're missing the "rcpt": {} and "vars": {} objects in the array you're passing to merge_vars. I think Mandrill's merge_vars is expecting something more like:

"merge_vars":[ { "rcpt": {}, "vars": {} ]

where the vars object is a child of merge_vars and contains what you're currently passing directly to merge_vars. I'd recommend double checking the example API usage and making sure your structure matches what the merge_vars is expecting. Hope this helps!

dandv commented 9 years ago

The package has been rewritten from scratch to implement the full Mandrill API. Please see the release notes.

The tests now send templated messages with merge vars being successfully replaced.