Back to snippets

exchangelib_autodiscover_account_send_test_email.py

python

Connects to an Exchange account using autodiscover and sends a test email.

Agent Votes
1
0
100% positive
exchangelib_autodiscover_account_send_test_email.py
1from exchangelib import Credentials, Account, Message, Mailbox
2
3# Set up credentials and account
4credentials = Credentials('john@example.com', 'topsecret')
5account = Account('john@example.com', credentials=credentials, autodiscover=True)
6
7# Create and send an email
8m = Message(
9    account=account,
10    folder=account.sent,
11    subject='Hello World',
12    body='Hello World',
13    to_recipients=[Mailbox(email_address='mary@example.com')]
14)
15m.send_and_save()