Sending Meteors verification email with Mandrill


#1

I’m using wylio’s mandrill package to send all emails in my application.
The docs say, that it is possible to customize the emails sent out by meteors account package

Accounts.emailTemplates.enrollAccount.html
.resetPassword.html
.verifyEmail.html

my code looks like this:

Accounts.emailTemplates.verifyEmail.html = function (user, url) {
  try {
    result = Mandrill.templates.render({
      template_name: 'verify',
      template_content: [
        {
          name: 'verification_url',
          content: url
        }
      ],
      merge_vars: [
        {
          name: 'VERIFICATION_URL',
          content: url
        }
      ]
    });
  } catch (error) {
    console.error('Error while rendering Mandrill template', error);
  }
  console.log(result);
  return result.html;
}

result.html is correct. Also the merge vars seem to work.

But meteor still sends out the email with the default template (eg. plain text, not the mailchimp template ‘verify’).

Does anybody have any experience with this package? What am I missing?


#2

I think you also need to change the text version of the email by overwriting Accounts.emailTemplates.verifyEmail.text. I think also having a plain text version is best practice. If you don’t want that you can delete Accounts.emailTemplates.verifyEmail.text.


#3

Changing the text works fine.

But why is Accounts.emailTemplates.verifyEmail.html not working?


#4

Try Meteor.Mandrill.sendTemplate instead of Mandrill.templates.render

are you getting a response code from the Mandrill server?


#5

I am getting a response from the Mandrill server.
result.html is fine, it contains the right template and the merge vars (html and everything).

The email that is sent out by meteor strangely just does not use it.


#6

@generalledger Meteor.Mandrill.sendTemplate does not work.
The package readme says:
Meteor.Mandrill was replaced by Mandrill global.


#7

fixed it:

return result.data.html;

:see_no_evil:


#8

Are you able to track opens and clicks in Mandrill when sending a template this way?

When I use Mandrill’s sendTemplate API method to send transactional emails unrelated to meteor accounts, the Mandrill open and click tracking seems to work fine.

But accounts related emails sent by Meteor don’t seem to register clicks or opens. What is weird is that the links do have the http://mandrillapp.com/track/click style link cloaking, so users are definitely being routed through the Mandrill servers on a click.


#9

Because Meteor is sending the messages over SMTP (using process.env.MAIL_URL), you’re likely not going to get the added value of click tracking…


#10

Please see my solution here