我正在编写发送电子邮件的脚本。
下面是主文件代码:
import config
from exchangelib import Credentials, Account, Message, Mailbox
from exchangelib.errors import UnauthorizedError, TransportError
credentials = Credentials(
username=config.exchange_username,
password=config.exchange_password,
auth_method='ntlm',
)
account = Account(
primary_smtp_address=config.exchange_email,
credentials=credentials,
autodiscover=True,
)
下面是配置文件代码:
token = "6666666666:GGGGvbe-cHjjDjuUtRggHtGfFFfF"
exchange_username = 'Asdfgh'
exchange_password = 'AkjhHhgHGhV'
exchange_email = 'Asdfgh@example.com'
exchange_server = 'https://some.mail.gov/owa/'
我在互联网上发现错误发生在Credentials(username=config.exchange_username, password=config.exchange_password, auth_method='ntlm')
行,因为exchangeelib库的Credentials构造函数中没有auth_method
参数。而是使用auth_type
参数。已更改,但错误再次发生,说明为auth_type
如果我从代码中删除auth_method='ntlm'
,它会给出一个错误“Authorization error on the Exchange server:服务器未报告兼容的身份验证类型”
1条答案
按热度按时间myzjeezk1#
Credentials
类不接受auth_method
参数。如果要指定exchangeelib要使用的身份验证类型,请创建
Configuration
示例并使用auth_type
参数:在www.example.com上有很多关于如何连接到服务器的示例https://ecederstrand.github.io/exchangelib/#setup-and-connecting