Sending Emails With Custom Data/Helpers

Hi all,

just wondering if anyone has run into something similar:

Right now, I have an html template, which I run through juice and pass on down to SSR.compileTemplate and SSR.render, with custom data. You can see the basic outline below.

My question is this: once you start getting into large numbers of recipients, is there a better/more efficient way to handle this?

      if(Contacts.find({_id:to[x]}).count() !== 0){
        var recipient = Contacts.findOne({_id:to[x]});
        var emailData = {
          name: recipient.firstName + ' ' + recipient.lastName
        to =;

          to: to,
          from: from,
          subject: subject,
          html: SSR.render( 'htmlEmail', emailData )

I would expect that SSR.render is quite readable stream so maybe just use some placeholder in template and than replace it in that cycle with some regexp ?
Or the good old shell way: render it and split by regexp and than in cycle
header part template
than insert name
footer part template

Right, so maybe I should’ve explained a bit more – my template looks like this:

<template name="myEmail">
  <h1>Hi, {{name}}!</h1>
  <p>Email body</p>

Then I inline the styles with juice, and pass that to SSR.compileTemplate. I was more curious if there is an out-of-the-box method to handle multiple emails with dynamic recipients and data, or if my for loop is going to be a good way to handle that…

Here’s a functional approach that might let mongo be more efficient (with bonus points for functional style):

db.collection.find({ _id : { $in : to}}).each((recipient) => {