Add an attachment to Accounts.sendEnrollmentEmail()

Is there a way to add an attachment to an enrollment email? I know per the docs you can modify the headers, which are managed through MailComposer. I’m trying to figure out if I can hack the header object to add attachments through it. Has anyone done this before?

So the sendEnrollmentEmail function is pretty easy to find in the source code, and it’s pretty simple to understand if you’ve used the email module previously. For others wanting to do this, I just copied the source code and wrote my own sendCustomEnrollmentEmail function:

Accounts.sendCustomEnrollmentEmail = function (userId, attachments, email) {
  // XXX refactor! This is basically identical to sendResetPasswordEmail.

  // Make sure the user exists, and email is in their addresses.
  var user = Meteor.users.findOne(userId);
  if (!user)
    throw new Error("Can't find user");
  // pick the first email if we weren't passed an email.
  if (!email && user.emails && user.emails[0])
    email = user.emails[0].address;
  // make sure we have a valid email
  if (!email || !_.contains(_.pluck(user.emails || [], 'address'), email))
    throw new Error("No such email for user.");

  var token = Random.secret();
  var when = new Date();
  var tokenRecord = {
    token: token,
    email: email,
    when: when
  };
  Meteor.users.update(userId, {$set: {
    "services.password.reset": tokenRecord
  }});

  // before passing to template, update user object with new token
  Meteor._ensure(user, 'services', 'password').reset = tokenRecord;

  var enrollAccountUrl = Accounts.urls.enrollAccount(token);

  var options = {
    to: email,
    from: Accounts.emailTemplates.enrollAccount.from
      ? Accounts.emailTemplates.enrollAccount.from(user)
      : Accounts.emailTemplates.from,
    subject: Accounts.emailTemplates.enrollAccount.subject(user),
    attachments: attachments
  };

  if (typeof Accounts.emailTemplates.enrollAccount.text === 'function') {
    options.text =
      Accounts.emailTemplates.enrollAccount.text(user, enrollAccountUrl);
  }

  if (typeof Accounts.emailTemplates.enrollAccount.html === 'function')
    options.html =
      Accounts.emailTemplates.enrollAccount.html(user, enrollAccountUrl);

  if (typeof Accounts.emailTemplates.headers === 'object') {
    options.headers = Accounts.emailTemplates.headers;
  }

  Email.send(options);
};