如何解决尝试打印特定电子邮件地址中收到的电子邮件数量
我正在使用带有Exchangelib库的python中的一些代码,我正在尝试通过计数器打印特定电子邮件地址的列表,该计数器计算从该电子邮件地址接收的电子邮件数量。这是我的代码,但没有任何打印输出。
from exchangelib import Credentials,Account
from collections import defaultdict
emails = ['email1@example.com','email2@example.dk']
credentials = Credentials('random@user.dk','Brute')
account = Account('random@user.dk',credentials=credentials,autodiscover=True)
def count_senders(emails):
counts = defaultdict(int)
for email in emails:
counts[email.sender.email_address] += 1
return counts
print(counts)
解决方法
我在代码中看不到您的函数调用。也许是问题所在?
count_senders(emails)
另一个问题是您无法在返回之后进行打印。像这样更改功能顺序:
def count_senders(emails):
counts = defaultdict(int)
for email in emails:
counts[item.sender.email_address] += 1
print(counts)
return counts
更新: 尝试在运行代码之前放入真实的电子邮件和凭据。
emails = ['email1@example.com','email2@example.dk']
for email in emails:
credentials = Credentials(email,'Brute')
account = Account(email,credentials=credentials,autodiscover=True)
counts = defaultdict(int)
for item in account.inbox.all().order_by('-datetime_received')[:100]:
print(item.subject,item.sender,item.datetime_received)
counts[email.sender.email_address] += 1
print(counts)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。