code: function renderMessage(template, user, vars) {
      var appurl = app.getExternalUrl();
      var emailVars = _.defaults(vars || {}, template.templateVars || {}, config.templateVars || {}, {
        'appurl': appurl,
        'settings': app.config.settings
      });
      // XXX should use route resolution fns
      if (user && user.local.signupToken) {
        emailVars.signupLink = appurl + "/verification/" + user.local.signupToken;
      }
      if (user && user.local.resetToken) {
        emailVars.resetLink = appurl + "/forgot/" + user.local.resetToken;
      }
  
      var msgSubject = swig.render(template.subject, {locals:emailVars});
  
      var message = {
          from: template.from || config.from,
          to: template.to || user.local.email,
          subject: msgSubject,
      };
      if (template.replyTo) {
        message.replyTo = template.replyTo;
      }
  
      if (template.templatePath && template.templateName) {
        throw new Error("mail template configuration error: templatePath and templateName cannot both be set");
      }
  
      if (template.templatePath) {
        message.html = swig.renderFile(template.templatePath, emailVars);
        return message;
      } else {
        message.vars = emailVars;
        message.templateName = template.templateName;
        message.merge_language = template.merge_language || "mailchimp";
        return message;
      }
    }
docs: /*
  Template fields:
  Required:
  templatePath
  subject
  to (if user isn't specified)
  Optional:
  from (use config default if missing)
  templateVars (overridden by vars)