我正在尝试使用flufl.bounce扫描使用poplib下载的电子邮件,并检测退回的电子邮件地址。到目前为止,我得到的是很多空集。下面是一些示例代码:
import getpass, poplib, email
from flufl.bounce import scan_message
user = 'redacted@redacted.com'
mail = poplib.POP3_SSL('redacted.redacted.com', '995')
mail.user(user)
mail.pass_('redacted')
num_messages = len(mail.list()[1])
for i in range(num_messages):
for msg in mail.retr(i+1)[1]:
msg = email.message_from_string(msg)
bounce = scan_message(msg)
print bounce
mail.quit()而print bounce给了我一个空集:
set([])此邮箱中有各种类型的退回邮件,我甚至可以使用mail.retr选择一个我知道是退回邮件的退回邮件,但当我将其馈送到scan_message中时,我仍然收到一个空集。我做错了什么?flufl.bounce docs在这里似乎没有多大帮助。
发布于 2013-11-12 07:58:30
好了,我明白了。msg是电子邮件元素的列表。因此,在将其提供给email.message_from_string()之前,我必须将它与\n连接在一起,而不是遍历mail.retr(i+1)[1],这给了我一个scan_message可以使用的适当消息。以下是工作代码
import getpass, poplib, email
from flufl.bounce import scan_message
user = 'redacted@redacted.com'
mail = poplib.POP3_SSL('mail.redacted.com', '995')
mail.user(user)
mail.pass_('redacted')
num_messages = len(mail.list()[1])
for i in range(num_messages):
x = mail.retr(i+1)[1]
msg = email.message_from_string("\n".join(x))
bounce = scan_message(msg)
print bounce
mail.quit()https://stackoverflow.com/questions/19896199
复制相似问题