[英]Get emails with imap_tools with python
我想接收來自特定發件人的所有今天的 email 文本,並使用 imap-tools 將它們放入 outlook 的列表中
我做了以下 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
使用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
IMAP 中沒有按時間過濾,只有按日期過濾。
在客戶端按時間過濾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.