[英]Get emails with imap_tools with python
I want to receive all the today's email texts from a specific sender and put them into a list from outlook with imap-tools我想接收来自特定发件人的所有今天的 email 文本,并使用 imap-tools 将它们放入 outlook 的列表中
I have made the following function but the problem is that it doesn't retrieve emails from 12:00AM - 12:00PM, is there any way to specify the hours for getting the proper messages?我做了以下 function 但问题是它不会从上午 12:00 到下午 12:00 检索电子邮件,有没有办法指定获取正确消息的时间?
def get_emails(username, password, sender):
from imap_tools import MailBox, A
emails = []
with MailBox('outlook.office365.com').login(username, password, 'INBOX') as mailbox:
for msg in mailbox.fetch(
A(
A(date_gte=datetime.date.today()), # get the today's emails
A(from_=sender), # from the specific senderEmailAddress
),
mark_seen = True
):
if msg.subject == "Subject":
emails.append(msg.text)
return emails
Use date
( imap_tools
documentation ):使用
date
( imap_tools
文档):
from imap_tools import MailBox, A
def get_emails(username, password, sender):
emails = []
with MailBox('outlook.office365.com').login(login_name, login_password, 'INBOX') as mailbox:
for msg in mailbox.fetch(
A(date=datetime.date.today(), from_=sender),
mark_seen = True
):
if msg.subject == "Subject":
emails.append(msg.text)
return email
There is no filter by time in IMAP, only by date. IMAP 中没有按时间过滤,只有按日期过滤。
Filter by time on client.在客户端按时间过滤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.