我是python的新手,我正在尝试做以下事情:
使用python脚本列出exchange上特定文件夹中的最后10封电子邮件,但我一直收到以下错误
exchangelib.errors.ErrorNonExistentMailbox: No mailbox with such guid下面是我正在尝试运行的脚本:
#!/usr/bin/env python
#coding:utf-8
from datetime import timedelta
from exchangelib import DELEGATE, IMPERSONATION, Account, Credentials, EWSDateTime, EWSTimeZone, Configuration, CalendarItem, Message, Mailbox, Attendee, Q, ExtendedProperty, FileAttachment, ItemAttachment, HTMLBody, Build, Version
from exchangelib import Configuration, GSSAPI, SSPI
from exchangelib.util import PrettyXmlHandler
from exchangelib.protocol import BaseProtocol, NoVerifyHTTPAdapter
import logging
import requests
logging.basicConfig(level=logging.DEBUG, handlers=[PrettyXmlHandler()])
def connect_exchange(account):
exCredentials = Credentials(username='User@Domainname.com', password='**********')
exConfig = Configuration(server='mail.domainname.com', credentials=exCredentials)
account = Account(primary_smtp_address='User@Domainname.com', credentials=exCredentials, config=exConfig, autodiscover=False, access_type=DELEGATE)
BaseProtocol.HTTP_ADAPTER_CLS = NoVerifyHTTPAdapter
# Print first 100 inbox messages in reverse order
for item in account.inbox.all().order_by('-datetime_received')[:10]:
print(item.subject, item.body, item.attachments)
connect_exchange()我可以看到我能够连接到邮件服务器,但是当脚本尝试时,似乎是在抛出上面的错误时出现for循环。
以前有没有人遇到过这样的错误?如果是这样的话,If有什么解决办法吗?
谢谢
发布于 2021-06-30 16:41:48
这是服务器告诉您,它不知道具有该名称的邮箱。也许你连接到了错误的服务器,或者你拼错了电子邮件地址,或者电子邮件地址是真实邮箱的别名?
发布于 2021-07-01 15:25:49
我在我的机器上测试了你的代码片段,只需很少的修改,它就能很好地为我工作。请检查您的设置凭据是否有任何拼写错误。
BaseProtocol.HTTP_ADAPTER_CLS = NoVerifyHTTPAdapter
logging.basicConfig(level=logging.DEBUG, handlers=[PrettyXmlHandler()])
def connect_exchange():
exCredentials = Credentials(username='admin@testexchange.local', password='Password')
exConfig = Configuration(server='testexchange.local', credentials=exCredentials)
account = Account(primary_smtp_address='user@testexchange.local', credentials=exCredentials, config=exConfig, autodiscover=False, access_type=DELEGATE)
# Print first 100 inbox messages in reverse order
for item in account.inbox.all().order_by('-datetime_received')[:10]:
print(item.subject, item.body, item.attachments)
connect_exchange()https://stackoverflow.com/questions/68116572
复制相似问题