问题描述
如果在过去24小时内未找到电子邮件,如何发出警报/例外?
这是打印的输出(如果找到电子邮件)。它会打印电子邮件地址,主题和计数。一行
defaultdict(
,{('[email protected]','备份状态报告(错误):Tesla(D)(星期一,14/09/2020)'):1})
如果未找到任何内容,这是打印输出。
defaultdict(
,{})
from exchangelib import Credentials,Account,UTC_NOW
from collections import defaultdict
from datetime import timedelta
credentials = Credentials('[email protected]','private')
a = Account('[email protected]',credentials=credentials,autodiscover=True)
counts = defaultdict(int)
testfolder = a.inbox.parent / 'Test'
since = UTC_NOW() - timedelta(hours=24)
for item in testfolder.all()\
.only('sender','subject')\
.filter(datetime_received__gt=since)\
.order_by('-datetime_received'):
if item.sender.email_address == '[email protected]':
counts[item.sender.email_address,item.subject] += 1
if not testfolder.filter(datetime_received__gt=since,sender='[email protected]').exists():
print('no email found')
print(counts)
以上代码已编辑为以下答案,但仍会打印空字典
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)