[英]Find messages by sender IMAP.search()
I use the imaplib library to work with emails. 我使用imaplib库处理电子邮件。 I want to find all emails from one person. 我想查找一个人的所有电子邮件。 The next code doesn't work for all messages: 下一个代码不适用于所有消息:
typ, data = con.search(None, 'FROM "name.surname@testmail.com"')
sometimes I need to set something like this to find that messages: 有时我需要设置类似以下内容以查找该消息:
typ, data = con.search(None, 'FROM "Surname, Name"')
and I cannot find a message by email. 而且我无法通过电子邮件找到消息。 If I understand correct, it's only for messages in html format. 如果我理解正确,则仅适用于html格式的邮件。
print(message['From'])
print(type(message['From']))
That code will print next: 该代码将在下面打印:
"Surname, Name" <name.surname@testmail.com>
<class 'str'>
Why search function doesn't search in this string all possible mentions? 为什么搜索功能不搜索所有可能提及的字符串? Doesn't it work like a normal string search? 它不像普通的字符串搜索那样工作吗? How should I search, if I want to find all messages with email '@testmail.com', not from a specific person? 如果要查找所有带有电子邮件“ @ testmail.com”的邮件,而不是来自特定人员的邮件,该如何搜索?
I have found an answer here: IMAP search for email address in the from field 我在这里找到了答案: IMAP在“发件人”字段中搜索电子邮件地址
Just use next as a filter: 只需将next用作过滤器:
(HEADER FROM "name.surname@testmail.com")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.