title: Batch emailing with Mailgun and Node.js
body: <p>I'm using the Mailgun node.js module to send batch emails out.</p>
  
  <p>According to the big yellow warning message in the <a href="https://documentation.mailgun.com/en/latest/user_manual.html#batch-sending" rel="nofollow noreferrer">official docs</a>, specifying recipient vars should result in sending "each recipient an individual email with only their email in the to field."</p>
  
  <p>However, my recipients can see all of the "to" addresses. I am successfully using recipient-vars to set the email subject for users, so it does appear that these are being read in correctly.</p>
  
  <p>Note that I am sending an HTML email using MIME. I tried this with the more straight-forward plain text variation, and it did appear to work.</p>
  
  <p>Is anyone able to help me understand why my recipients can see all other recipients? Am I doing something wrong, or does this functionality not work for Mailgun MIME emails?</p>
  
  <pre><code>// recipients
  var recipients = ['email1@email1.com', 'email2@email2.com', 'email3@email3.com'];
  var recipientVars = {
      'email1@email1.com': {
          id: 1,
          subject: 'Subject 1'
      },
      'email2@email2.com': {
          id: 2,
          subject: 'Subject 2'
      },
      'email3@email3.com': {
          id: 3,
          subject: 'Subject 3'
      }
  };
  
  // options
  var options = {
      from: 'Me &lt;me@me.com&gt;',
      to: recipients,
      'recipient-variables': recipientVars,
      subject: '%recipient.subject%',
      text: myMailText,
      html: myMailHTML,
      headers: {
          'X-Mailgun-Recipient-Variables': JSON.stringify(recipientVars)
      }
  };
  
  // create mail
  var mail = new nodemailer(options);
  
  // send mail
  mail.compile().build((err, message) =&gt; {
      var mailData = {
          to: recipients,
          message: message.toString('ascii'),
          'recipient-variables': recipientVars
      };
      mailgun.messages().sendMime(mailData, (err, res) =&gt; {
          console.log(res);
      });
  });
  </code></pre>