mailgun-js-boland
mailgun-js-boland copied to clipboard
How can I download attachment from mailgun
Could you show me how can i download attachment by the message url ?
I asked Mailgun support this wuestion and they anwered with:
I tried using the request library from the mailgun-js sdk and I was still getting undefined errors. My hunch is the library my not fully support downloading of attachments.
The code they used:
var mailgun = require("mailgun-js");
var Request = require('mailgun-js/lib/request');
var DOMAIN = 'YOUR_DOMAIN_NAME';
var mailgun = require('mailgun-js')({apiKey: 'key-*****************', domain: 'DOMAIN_NAME'});
var options = {
//host will be either sw.api.mailgun.net or se.api.mailgun.net based on the full attachment storage url
host: 'sw.api.mailgun.net',
endpoint: '/v3',
protocol: 'https:',
port: 443,
auth: ['api', api_key].join(':'),
retry: 1
};
var req = new Request(options);
let response = req.request('GET', `/domains/${DOMAIN}/messages/ATTACHMENT_KEY`, function (error, body) {
console.log(body);
});
This was after I tested the same and only received 'undefined' in the 'body'. I guess my answer does not solve your problem :(
I do hope a contributor can answer this.
@bojand any updates on this.