在Python3.x中,您可以通过导入“imaplib”和“email”包以非常简单的方式完成这项工作。虽然这是一个老职位,但也许我的回答可以帮助这个职位的新人。status, data = self.imap.fetch(num, '(RFC822)')
email_msg = email.message_from_bytes(data[0][1]) #email.message_from_string(data[0][1])
#If message is multi part we only want the text version of the body, this walks the message and gets the body.
if email_msg.is_multipart():
for part in email_msg.walk():
if part.get_content_type() == "text/plain":
body = part.get_payload(decode=True) #to control automatic email-style MIME decoding (e.g., Base64, uuencode, quoted-printable)
body = body.decode()
elif part.get_content_type() == "text/html":
continue
现在您可以打印body变量,它将是纯文本格式:)如果它对您足够好,那么选择它作为接受的答案将是很好的。