发布时间:2019-07-24 09:50:17编辑:auto阅读(1976)
安装库exchangelib
pip install exchangelib
脚本内容
# coding=utf-8
#
# Created on 2018/2/
from exchangelib import DELEGATE, Account, Credentials, Configuration, NTLM, Message, Mailbox, HTMLBody
from exchangelib.protocol import BaseProtocol, NoVerifyHTTPAdapter
#此句用来消除ssl证书错误,exchange使用自签证书需加上
BaseProtocol.HTTP_ADAPTER_CLS = NoVerifyHTTPAdapter
# 输入你的域账号如example\leo
cred = Credentials(r'EXAMPLE\leo', '输入你的密码')
config = Configuration(server='输入邮箱服务器网页地址', credentials=cred, auth_type=NTLM)
a = Account(
primary_smtp_address='输入你要绑定的邮箱名(leo@example.com)', config=config, autodiscover=False, access_type=DELEGATE
)
# 此处为用来发送html格式邮件的文件路径
with open(r'C:\Users\leo\Desktop\1.html') as f:
msg = f.read().decode('utf-8')
m = Message(
account=a,
folder=a.sent,
subject=u'测试邮件',
body=HTMLBody(msg),
to_recipients=[Mailbox(email_address='输入你要绑定的邮箱名(leo@example.com)')]
)
m.send_and_save()
上一篇: 使用Python写CUDA程序
下一篇: Python魔方方法详解
48899
47983
38756
35891
30318
27086
26097
20929
20750
19111
591°
669°
661°
666°
636°
609°
688°
755°
879°
1036°