Have you seen this tutorial?
Getting attachment from mailgun
Unsure if this is the right place to ask but I'm trying to setup inbound emails. I've got it so my application accepts emails via a webhook and now I'm trying to use the Guzzle client to request the file and store it into my local storage folder.
{
$files = collect(json_decode($request->input('attachments'), true))
->filter(function ($file) {
return $file['content-type'] == 'application/pdf';
});
if ($files->count() === 0) {
return response()->json([
'status' => 'error',
'message' => 'Missing expected PDF attachment'
], 406);
}
foreach($files as $file){
$response = (new Client())->get($file['url'], [
'auth' => ['api', config('services.mailgun.secret')],
]);
$pdf = $response->getBody();
Storage::put($file['name'], $pdf);
}
return response()->json(['status' => 'ok'], 200);
}
This is the code that is not working:
$response = (new Client())->get($file['url'], [
'auth' => ['api', config('services.mailgun.secret')],
]);
Example of what is stored in $file['url']
Error:
[2019-01-05 03:36:50] local.ERROR: Client error: `GET https://se.api.mailgun.net/v3/domains/sandboxf0ce04d10b4b4c1287962dda52b3e7a6.mailgun.org/messages/eyJwIjpmYWxzZSwiayI6ImZhNjI5NTY1LTMwYjUtNDYxZi1iNTQ1LWUwOWM2NTQ3NjA0MyIsInMiOiIxYWFiMWI1MTQ3IiwiYyI6InRhbmtiIn0=/attachments/0` resulted in a `401 UNAUTHORIZED` response: Forbidden
Now I understand that for some reason it's not authenticating correctly but unsure why when I'm passing through the correct Application Secret Key. I've read on the internet it may just be a sandbox issue but wanted some insight before attempting live.
Please or to participate in this conversation.