Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Mailgun.js offer the possibility to send a template?

So MailGun offers the possibility to send email via their Node library that implements their API:

var mailgun = require('mailgun-js')({ apiKey: api_key, domain: DOMAIN });

var filepath = path.join(__dirname, 'sample.jpg');

var data = {
  from: 'Excited User <[email protected]>',
  to: '[email protected], [email protected], [email protected]',
  cc: '[email protected]',
  bcc: '[email protected]',
  subject: 'Complex',
  text: 'Testing some Mailgun awesomness!',
  html: "<html>HTML version of the body</html>",
  attachment: filepath
};

mailgun.messages().send(data, function (error, body) {
  console.log(body);
});

And they also offer the possibility to design and create Email Templates. Is there any way to send templated emails with some custom variables via their API? Something like:

var data = {
  from: 'Excited User <[email protected]>',
  to: '[email protected], [email protected], [email protected]',

  template: "withdraw_request_approved", //Instead of 'html'
  vars: { firstName: 'John', lastName: 'Doe' }
};

mailgun.messages().send(data, function (error, body) {
  console.log(body);
});

If not, could you suggest some other mailing service that offer this kind of functionality? (I've skipped Mandrill since it's apparently currently down, with no clear estimate to when it'll become available again)

like image 764
iuliu.net Avatar asked Dec 04 '22 19:12

iuliu.net


1 Answers

Yes, you can, following would be the format in your case:

var data = {
  from: 'Excited User <[email protected]>',
  to: '[email protected], [email protected], [email protected]',

  template: "withdraw_request_approved", //Instead of 'html'
  'v:firstName': 'John',
  'v:lastName': 'Doe'
};
like image 90
adnan kamili Avatar answered Jan 10 '23 02:01

adnan kamili