How do you send customized verification mails?

I’m trying to create not ugly verification emails, so some predefined templates need to be used. With Blaze being somewhat obsolete and us trying to get rid of it, this doesn’t seem like a long term solution, on top of that though Blaze.toHTMLWithData doesn’t work on the server anyway, so it’s not possible to pass some data to the template and have it sent properly.

How do you solve this issue?

Use ES2015 template strings? And if you are trying to make a nice HTML email your best bet is probably to use some sort of special email tool/service because writing an HTML email that works across different clients is a nightmare.

We use mautic (visit http://mautic.org) for all our automated marketing emails. Check it out. Competes with HubSpot while being open source

Anyone tried https://mjml.io/?

Mandrill can do this. Mailchimp for the design, then Mandrill for the transactional emails.

The Mandrill package has an example.

2 Likes

I’m currently using meteorhacks:ssr and it works great - it compiles Blaze HTML templates from static files and lets you render them with your data. It works like this:

// Template map
var emailTemplates = {
  'emailLayout': 'layout.html', // Layout template for common email header/footer
  'invitation': 'invitation.html',
  ...
};

// Compile HTML templates, they should be stored in private/ directory
Meteor.startup(function() {
  for (var template in emailTemplates) {
    SSR.compileTemplate(template, Assets.getText('email/' + emailTemplates[template]) );
  }
});

// Function to send emails, data is an object with your template data
sendEmail = function(to, subject, template, data) {
  Email.send({
    to: to,
    from: emailFrom,
    subject: subject,
    html: SSR.render(template, data)
  });
};

Layout email template contains a {{> Template.contentBlock}} directive, and then I can do this for example in invitation template:

{{#emailLayout}}
    {{invitee}} has invited you...
{{/emailLayout}}

Note that with SSR package you omit <template> tags in your HTML.

1 Like

Yea, I was looking for something like this! Just too bad Mandrill is not exactly startup friendly with 10$ already from the start with barely any email traffic :frowning: Will try to see if competitors offer this with a free tier or worst case guess I have to pay from the start.

One thing you can also do is use Mailchimp to format the email, then export the format into HTML. Then you can use that HTML in a template. The HTML is pretty large, but if you do this you can bypass Mandrill and just send it straight from the Meteor app.

As @sashko mentioned you really don’t want to try to create these emails yourself because of all the old email clients you’d have to try to support (like Outlook, which uses Word to render the HTML!). So for me the best part of using the Mailchimp/Mandrill method is Mailchimp’s UI for building an email. Even if you don’t use a transactional service like Mandrill you are going to want to find a service that can build the email in a way that works for many different email clients.

1 Like