I'm using the Mailgun node.js module to send batch emails out.
According to the big yellow warning message in the official docs, specifying recipient vars should result in sending "each recipient an individual email with only their email in the to field."
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.
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.
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?
// recipients
var recipients = ['[email protected]', '[email protected]', '[email protected]'];
var recipientVars = {
'[email protected]': {
id: 1,
subject: 'Subject 1'
},
'[email protected]': {
id: 2,
subject: 'Subject 2'
},
'[email protected]': {
id: 3,
subject: 'Subject 3'
}
};
// options
var options = {
from: 'Me <[email protected]>',
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
mailpile().build((err, message) => {
var mailData = {
to: recipients,
message: message.toString('ascii'),
'recipient-variables': recipientVars
};
mailgun.messages().sendMime(mailData, (err, res) => {
console.log(res);
});
});
I'm using the Mailgun node.js module to send batch emails out.
According to the big yellow warning message in the official docs, specifying recipient vars should result in sending "each recipient an individual email with only their email in the to field."
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.
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.
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?
// recipients
var recipients = ['[email protected]', '[email protected]', '[email protected]'];
var recipientVars = {
'[email protected]': {
id: 1,
subject: 'Subject 1'
},
'[email protected]': {
id: 2,
subject: 'Subject 2'
},
'[email protected]': {
id: 3,
subject: 'Subject 3'
}
};
// options
var options = {
from: 'Me <[email protected]>',
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.pile().build((err, message) => {
var mailData = {
to: recipients,
message: message.toString('ascii'),
'recipient-variables': recipientVars
};
mailgun.messages().sendMime(mailData, (err, res) => {
console.log(res);
});
});
Share
Improve this question
asked Mar 27, 2018 at 9:16
AlexAlex
1,4011 gold badge19 silver badges31 bronze badges
1 Answer
Reset to default 10Seems this functionality doesn't work with sendMime()
method, but it does with regular send()
method even without any mail pilation. Here is working code snippet:
const mailgun = require('mailgun-js')({
apiKey: 'api_key',
domain: 'domain'
});
const recipients = ['[email protected]', '[email protected]'];
const recipientVars = {
'[email protected]': {
id: 1,
subject: 'Subject 1',
name: 'Name 1'
},
'[email protected]': {
id: 2,
subject: 'Subject 2',
name: 'Name 2'
}
};
const envelope = {
from: 'Sender <[email protected]>',
to: recipients,
subject: '%recipient.subject%',
html: 'Hey <strong>%recipient.name%<strong>',
'recipient-variables': recipientVars,
};
mailgun.messages().send(envelope, function (error, body) {
console.log(body);
});
As you would notice all placeholders are populated and <strong>
tag properly rendered.