Python 之 调用Exchange邮件接口发送邮件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 之 调用Exchange邮件接口发送邮件相关的知识,希望对你有一定的参考价值。
调用Exchange邮件接口发送邮件
1、安装exchangelib库
pip3 install exchangelib
2、编写调用exchangelib库,发送邮件
#Author Kang
from exchangelib import DELEGATE, Account, Credentials, Message, Mailbox, HTMLBody
def Email(to, subject, body):
creds = Credentials(
username=‘zhoumingkang‘,
password=‘帐号验证的密码‘
)
account = Account(
primary_smtp_address=‘[email protected]‘,
credentials=creds,
autodiscover=True,
access_type=DELEGATE
)
m = Message(
account=account,
subject=subject,
body=HTMLBody(body),
to_recipients = [Mailbox(email_address=to)]
)
m.send()
cpu = 80
mem = 70
message = ‘‘‘-----------运维报告------------<br>
CPU使用率:%s<br>
可用内存:%s<br>
‘‘‘ %(cpu,mem)
Email("[email protected]","主题",message)
3、邮件内容
以上是关于Python 之 调用Exchange邮件接口发送邮件的主要内容,如果未能解决你的问题,请参考以下文章