EWS sendEmailDemo
# exchange
from exchangelib import DELEGATE, Account, Credentials, Configuration, Build, Version, Message, Mailbox, HTMLBody,NTLM,IMPERSONATION
from exchangelib.protocol import BaseProtocol, NoVerifyHTTPAdapter
import urllib3
#忽略警告
urllib3.disable_warnings()
#要是一直有max retries exceeded with url,一定要加这句
version = Version(build=Build(15,0,12,34))
#此句用来消除ssl证书错误,exchange使用自签证书需加上
BaseProtocol.HTTP_ADAPTER_CLS = NoVerifyHTTPAdapter
# 输入你的域账号如example\leo
cred = Credentials('****\\****', ****')
config = Configuration(service_endpoint='https://****/ews/Exchange.asmx', credentials=cred, version=version, auth_type=NTLM)
a = Account(
primary_smtp_address='***@*****.com',
config=config,
autodiscover=False,
access_type=DELEGATE,
)
m = Message(
account=a,
folder=a.sent,
subject=u'测试邮件',
body=HTMLBody('test'),
#发送多人用[Mailbox(email_address='***@*****.com'),Mailbox(email_address='***@*****.com')...]
to_recipients=[Mailbox(email_address='***@*****.com')]
)
m.send_and_save()
这个我真的调了好久才测通,
如果帮助到你,能点个赞吗?