python接收邮件内容启动程序,提取电子邮件收到:标题与Python电子邮件包

I'd like to extract the Final Received: email header from a message. I have the Message as returned from email.message_from_file().

Using the Message.get() or Message.get_item() methods don't guarantee which of the many Received: headers I will get. Message.get_all() returns them all, but doesn't guarantee an order. Is there a way to be guaranteed to get the last one?

解决方案

Received: headers are timestamped:

Received: from lb-ex1.int.icgroup.com (localhost [127.0.0.1])

by lb-ex1.localdomain (Postfix) with ESMTP id D6BDB1E26393

for ; Fri, 12 Dec 2014 12:09:24 -0500 (EST)

So, do messageInstance.get_all() and sort the resulting list however you see fit, an example of how to do this:

import email.utils

import operator

def sort_key(received_header):

received_date = email.utils.parsedate_tz(received_header)

return received_date

received_header_list.sort(key=sort_key)

If it doesn't work, do leave a comment and I'll be happy to look into it further.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值