gpt4 book ai didi

python - IMAP4.按主题名称搜索 python

转载 作者:太空宇宙 更新时间:2023-11-03 19:41:39 25 4
gpt4 key购买 nike

如何解析包含特定名称文件的电子邮件,我无法使用 SUBJECT 进行解析,因为它是空的

最佳答案

我还没有对此进行测试,但如果它有一个具有您指定名称的文件,它应该打印邮件 ID。

import imaplib
import email

file_name = ""
server_outgoing = ""
username = ""
password = ""

connection = imaplib.IMAP4_SSL(server_outgoing)
connection.login(username, password)

connection.select("inbox")
status, mail_datas = connection.search(None, 'ALL')

mail_ids = []
for mail_data in mail_datas:
mail_ids += mail_data.split()

for mail_id in mail_ids:
status, data = connection.fetch(mail_id, '(RFC822)')
message = email.message_from_bytes(data[0][1])

if message.is_multipart():
for part in message.get_payload():
filename = part.get_filename()
if(filename == file_name):
print(mail_id)

关于python - IMAP4.按主题名称搜索 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60390531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com