Python 之 調用Exchange郵件接口發送郵件
阿新 • • 發佈:2019-01-24
安裝 author EDA 可用內存 jpg chan access cover auto 調用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郵件接口發送郵件