mailgun-js-boland icon indicating copy to clipboard operation
mailgun-js-boland copied to clipboard

How can I download attachment from mailgun

Open thiennhan2310 opened this issue 6 years ago • 2 comments

Could you show me how can i download attachment by the message url ?

thiennhan2310 avatar Apr 03 '18 08:04 thiennhan2310

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.

YuvalKaplan avatar Apr 09 '18 17:04 YuvalKaplan

@bojand any updates on this.

ziedmahdi avatar Feb 28 '19 09:02 ziedmahdi