# exchangelib.errors.AutoDiscoverFailed
from exchangelib import DELEGATE, Account, Credentials, Message, Mailbox, HTMLBody,Configuration,NTLM
from exchangelib.protocol import BaseProtocol,NoVerifyHTTPAdapter
BaseProtocol.HTTP_ADAPTER_CLS = NoVerifyHTTPAdapter
def Email(to, subject, body):
creds = Credentials(
username='xxx.com\exadmin',
password='Spinfo0'
)
config = Configuration(server='xxx.com', credentials=creds, auth_type=NTLM)
account = Account(
primary_smtp_address='xxx@xxx.com',
credentials=creds,
autodiscover=False,
access_type=DELEGATE,
config=config
)
m = Message(
account=account,
subject=subject,
body=HTMLBody(body),
to_recipients = [Mailbox(email_address=to)]
)
m.send()
Email("xxx@xxx.com", "abc", "def")
网友评论