Really appreciate this module so far. I use it for all my Mailgun routes except MIME. I tried adding it myself but could not get it to work. My use case is sending calendar invites -- Outlook only recognizes ICS files sent as 'alternative messages' vs attachments, but Mailgun's regular API only supports text/html alternatives. My current solution is to use a separate mailgun node library (https://github.com/shz/node-mailgun), but it also uses the OLD Mailgun api at mailgun.net/api/. I also asked Mailgun if they could add 'calendar' as another format to their API, but seems unlikely.
Is there any work being done to support Mailgun's MIME route that I can help test? For the benefit of others, here's my final working code (caveat emptor: creating the ICS string is another fair challenge!). For this example, I'd like a 'sendRaw' method to be available in mailgun-js:
var mailgun = require('mailgun'); // node-mailgun
var mailcomposer = require('mailcomposer');
mailcomposer.setMessageOption({
from: '[email protected]',
to: [[email protected]],
body: "Hello world!",
html: '<strong>Hello world!</strong>',
subject: 'Well hello there!'
});
/* For Outlook */
mailcomposer.addAlternative({
contentEncoding: '7bit',
contents: ics_string,
contentType: 'text/calendar'
});
/* Google and everyone else */
mailcomposer.addAttachment({
contents: ics_string,
contentType: 'application/ics',
fileName: 'invite.ics'
});
mailcomposer.buildMessage(function (err, messageSource) {
var mailer = new mailgun.Mailgun(MAILGUN_API_KEY);
mailer.sendRaw('[email protected]', ['[email protected]'], messageSource, function (err) {
console.log(err || 'no error');
process.exit();
});
});