python发送邮件

Python 调用outlook发送邮件(转 )

寵の児 提交于 2019-11-26 12:09:48
单账号: import win32com.client as win32 def send_mail(): outlook = win32.Dispatch('Outlook.Application') mail_item = outlook.CreateItem(0) # 0: olMailItem mail_item.Recipients.Add('wang.jinweis@fokker.com') mail_item.Subject = 'Mail Test' mail_item.BodyFormat = 2 # 2: Html format mail_item.HTMLBody = ''' <H2>Hello, This is a test mail.</H2> Hello Guys. ''' mail_item.Send() if __name__ == '__main__': send_mail()    多账号: def send_mail(): outlook_app = win32.Dispatch('Outlook.Application') # choose sender account send_account = None for account in outlook_app.Session.Accounts: if account.DisplayName