【问题标题】:python poplib get headers from emailspython poplib从电子邮件中获取标题
【发布时间】:2018-05-22 14:53:40
【问题描述】:

这是我的actula代码:

import poplib, sys, re, threading, time, Queue
from email import parser

    Mailbox = poplib.POP3(pop3, '110')
    Mailbox.user(username)
    Mailbox.pass_(password)
    numMessages = len(Mailbox.list()[1])
    for i in range(numMessages):
            fullemail = ''
            fullemail = '\n'.join([msg for msg in Mailbox.retr(i+1)[1]])
            msg = parser.Parser().parsestr(fullemail)
            for part in msg.walk():
                    print part.get_payload(decode=True)

print part.get_payload(decode=True) 打印邮件正文,如何打印邮件标题?

【问题讨论】:

标签: python email pop3 poplib


【解决方案1】:

email.message.Message/email.message.EmailMessage 对象的方法items() 可能有用:

for t in msg.items():
    print(t)

t 是这样的元组(key,value).

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    相关资源
    最近更新 更多