Reputation: 2008
I have a node endpoint that receives an incoming email in json, complete with any attachments from mailgun.
The attachments are in a json array (xxx.com is used for privacy)
attachments: '[{"url": "https://sw.api.mailgun.net/v3/domains/xxx.com/messages/eyJwIjpmYWxzZSwiayI6ImZhMTU0NDkwLWVmYzgtNDVlNi1hYWMyLTM4M2EwNDY1MjJlNCIsInMiOiI2NmU1NmMzNTIwIiwiYyI6InRhbmtiIn0=/attachments/0", "content-type": "image/png", "name": "ashfordchroming_logo.png", "size": 15667}]
But if i type the url in the browser:
I get
{
"message": "Domain not found: xxx.com"
}
I wanted the simplest way to show the image attachment in HTML, I was hoping the URL would just work since mailgun store the attachment.
So I was just trying to render the url in a template from Node.
Do I need to attach auth / API key credentials to the front of the URL to do this to test and make work?
Upvotes: 3
Views: 1580
Reputation: 49
If you want to access the raw json, go to
using username 'api' and password 'your-mailgun-privatekey'.
To do this programmatically, use the request package to read the buffer.
const rp = require("request-promise");
let file = rp.get({
uri: "attachement-url",
headers: {
"Accept": "message/rfc2822"
}
}).auth("api", "your private key")
/**Access the buffer here**/
file.on('data', (s => {
console.log(s)
}))
file.pipe(fs.createWriteStream("./my-image.jpg"))
you can pipe the file to S3 or any cloud bucket.
Upvotes: 5