我正在使用aiohttp。我有一个api来处理邮件路由数据。电子邮件有多个附件。我不能阅读所有的附件。它只给了我一个。
data是我收到的。
str(list(data.keys()))给了我清单- ['Content-Type', 'Date', 'Dkim-Signature', 'From', 'Message-Id', 'Mime-Version', 'Received', 'Received', 'Received', 'Subject', 'To', 'X-Envelope-From', 'X-Mailgun-Incoming', 'X-Received', 'attachment-count', 'body-html', 'body-plain', 'from', 'message-headers', 'recipient', 'sender', 'signature', 'stripped-html', 'stripped-signature', 'stripped-text', 'subject', 'timestamp', 'token', 'attachment-1']
当我在电子邮件中发送多个文件时,str(data.get('attachment-count')给了我2/3/4 --这很好。但是只有一个键是attachment-1。
怀疑:
键中的attachment-1是否表明data中只有一个文件
如果有多个文件,这是否意味着有密钥作为- attachment-1,attachment-2 .
如何从电子邮件中检索所有文件?
我试着寻找Mailgun的文档,但在阅读文件时没有得到具体的帮助。有人能帮我重定向相同的代码吗。其他字段如from、subject也很好。
我尝试过的这个随机的东西也只读取一个文件。但这似乎是不对的。
form_data_content_type = [(v.name, v.content_type, v.filename) if (
v and hasattr(v, 'content_type') and hasattr(v, 'filename')) else None for v in
data.values()]
logger.info("No. of attachments " + str(len(form_data_content_type)) # returns 1 * UPDATE *
我试着运行一个烧瓶服务器并测试多个文件的电子邮件:
print(request.files)打印ImmutableMultiDict([('attachment-2', <FileStorage: 'Screen Shot 2015-09-02 at 10.18.37 am.png' ('image/png')>), ('attachment-1', <FileStorage: 'Screen Shot 2015-09-02 at 10.18.36 am.png' ('image/png')>)])
这表明确实有两个文件。
现在,关于aiohttp如何处理mailgun的数据,确实存在一个问题:
打印request.post()只提供一个文件- 'attachment-1': Field(name='attachment-1', filename='Screen Shot 2015-09-02 at 10.40.18 am.png', file=<_io.BufferedRandom name=10>, content_type='image/png')。没有附件-2,天知道为什么!
发布于 2018-04-29 21:03:35
由于我不熟悉python或aiohttp,所以我不能给您提供代码示例,但这就是它的工作方式。
post 邮箱发送包含所有相关信息的post请求作为数组,
files 它还将文件与请求一起发送,在php中,您可以通过超级全局$_FILES循环检索附件,
内嵌图像
当有人发送内联图片(例如myimg.jpg )时,您需要将附件映射到嵌入式,这就是为什么您只看到attachment-1的原因,即使有更多的附件,其中只有一个是嵌入的。
'attachment-count' => '3',告诉您在php中有多少附件(在本例中为3 ),您可以在$_FILES,中找到它
content-id-map' => '{"<ii_jgl9284x0_1631307716495e75>": "attachment-1"}',指向嵌入的img
<img src="cid:ii_jgl9284x0_1631307716495e75" width="190" height="114">https://stackoverflow.com/questions/32332473
复制相似问题