...

Python发送Exchange邮件

安装exchangelib

参考:https://pypi.org/project/exchangelib/

pip install exchangelib

发送邮件集附件

from exchangelib import DELEGATE, IMPERSONATION, Account, Credentials, Message, HTMLBody, Mailbox, FileAttachment

account = Account('***@***',
                  credentials=Credentials(username='***@***', password='***'),
                  autodiscover=True)

m = Message(
        account=account,
        subject='测试带附件下',
        body=HTMLBody('<h2>hello with attachment</h2>'),
        to_recipients=[Mailbox(email_address='superhin@126.com')]
    )

m.attach(FileAttachment(name='test.html', content=open('/result/test.html','rb').read()))
m.send()
posted @ 2021-06-22 11:58  韩志超  阅读(437)  评论(0编辑  收藏  举报