I am writing script to send email messages.
Here is the main file code:
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,
)
here is the config file code:
token = "6666666666:GGGGvbe-cHjjDjuUtRggHtGfFFfF"
exchange_username = 'Asdfgh'
exchange_password = 'AkjhHhgHGhV'
exchange_email = '[email protected]'
exchange_server = 'https://some.mail.gov/owa/'
I found on the Internet that the error occurs in the Credentials(username=config.exchange_username, password=config.exchange_password, auth_method='ntlm') line, since there is no auth_method parameter in the Credentials constructor in the exchangelib library. Instead, the auth_type parameter is used. Changed, but the error occurs again already with the description of auth_type
If I remove auth_method='ntlm' from the code, it gives an error "Authorization error on the Exchange server: No compatible auth type was reported by server"
The
Credentialsclass does not accept anauth_methodargument.If you want to specify the authentication type for exchangelib to use, create a
Configurationinstance and use theauth_typeargument:There are plenty of examples on how to connect to the server at https://ecederstrand.github.io/exchangelib/#setup-and-connecting