<commit_before>const debug = require('debug')('app:email');

const mandrill = require('mandrill-api/mandrill');
const { getVars, getTo } = require('./mandrill-utils');
const config = require('./config');
const emailConfig = config.get('email');
const mandrillClient = new mandrill.Mandrill(emailConfig.key);

const send = ({ email, to, cc, bcc, subject, message, template, vars }) => new Promise((resolve, reject) => {
  const mandrillMessage = {
    subject,
    to: getTo({ email, to, cc, bcc }),
    from_email: emailConfig.from,
    merge_vars: [{
      rcpt: email,
      vars: getVars(vars)
    }]
  };

  if (template) {
    return mandrillClient.messages.sendTemplate({
      template_name: template,
      template_content: [{}],
      message: mandrillMessage,
      async: false
    }, resolve, reject);
  }

  return mandrillClient.messages.send({
    message: { ...mandrillMessage, text: message },
    async: false
  }, res => {
    debug('sent', res);
    resolve(res);
  }, err => {
    debug('error', err);
    reject(err);
  });
});

module.exports = { send };<commit_msg>Debug sending email by template<commit_after>const debug = require('debug')('app:email');

const mandrill = require('mandrill-api/mandrill');
const { getVars, getTo } = require('./mandrill-utils');
const config = require('./config');
const emailConfig = config.get('email');
const mandrillClient = new mandrill.Mandrill(emailConfig.key);

const send = ({ email, to, cc, bcc, subject, message, template, vars }) => new Promise((resolve, reject) => {
  const mandrillMessage = {
    subject,
    to: getTo({ email, to, cc, bcc }),
    from_email: emailConfig.from,
    merge_vars: [{
      rcpt: email,
      vars: getVars(vars)
    }]
  };

  if (template) {
    return mandrillClient.messages.sendTemplate({
      template_name: template,
      template_content: [{}],
      message: mandrillMessage,
      async: false
    }, res => {
      debug('sent', res);
      resolve(res);
    }, err => {
      debug('error', err);
      reject(err);
    });
  }

  return mandrillClient.messages.send({
    message: { ...mandrillMessage, text: message },
    async: false
  }, res => {
    debug('sent', res);
    resolve(res);
  }, err => {
    debug('error', err);
    reject(err);
  });
});

module.exports = { send };
{'fraction_non_alphanumeric': 0.16746203904555315, 'fraction_numerical': 0.0, 'mean_word_length': 3.2942271880819365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3701876', 'n_tokens_mistral': 741, 'n_tokens_neox': 716, 'n_words': 170}