2017-05-06 47 views

回答

0

这不是最优雅的方式,但它的工作原理。我无法找到像这样的东西。所以如果你想下载邮件附件的邮件。

从收到的邮件

$request->input('sender') 

获取元数据JSON获取数据,我再说一遍附件的JSON附件

$request->input('attachments') 

示例元数据

'attachments' => '[ 
        { 
         "url": "https://se.api.mailgun.net/v3/domains/sandboxcXXXXXXXX19a57487.mailgun.org/messages/XXXXXXXXXXXXXXXXXXX=/attachments/0", 
         "content-type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", 
         "name": "Plan API end points XXXX.docx", 
         "size": 53185 
         } 
        ]', 

从电子邮件中获取文件

STEP 1. JSON解码第一附件

$files = json_decode($request->input('attachments'),true); 

STEP 2.使用作曲家安装mailgun API。 (https://github.com/mailgun/mailgun-php

第3步。创建一个新的mailgun实例并使用您的API密钥,而不是密码。

$mg = new Mailgun('key-xxxxxxxxxxxxxxxxx'); 
    foreach ($files as $file){ 
       $fileName = $file['name']; 
       $content = $mg->getAttachment($file['url'])->http_response_body; 
} 

就是这样,您现在可以下载$内容,放入您的云存储中,无论如何。