[英]Get the body of all unseen messages from an address IMAP Python
I would like to get the body of all unseen messages from an address using the IMAP library in Python 3. I was able to get all the message's body using this code here 我想使用Python 3中的IMAP库从某个地址获取所有看不见的邮件的正文。我可以在此处使用以下代码获取所有邮件的正文
import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login( 'EMAIL', 'PASSWORD' )
mail.list
mail.select("inbox")
obj, data = mail.search(None, 'ALL')
for num in data [0].split():
typ, data = mail.fetch(num, 'BODY[1]')
print('Message %s\n%s\n' % (num, data[0][1]))
mail.close()
Is there any way that I could narrow the search to just return unseen messages from a single address like email@address.com? 有什么方法可以缩小搜索范围,以便仅从单个地址(例如email@address.com)返回看不见的邮件? This site here shows the unseen flag and this user was able to get a list of email addresses that I have received emails from using this script here .
此站点在此显示了未标记,该用户能够从此处使用此脚本获取我收到的电子邮件地址列表。 I was unable to figure out how to change the code to work because it was missing parts.
我无法弄清楚如何更改代码以使其正常工作,因为它缺少部分。 Is there some way to combine these three to achieve the results I need?
有什么方法可以将这三个方法结合起来以获得所需的结果?
Replace ALL
with UNSEEN
. 用
UNSEEN
代替ALL
。 IMAP has many search keys you can use, ALL
is not the only one. IMAP有许多可以使用的搜索键 ,而
ALL
并不是唯一的搜索键 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.