Skip to main content
 首页 » 编程设计

python之如何使用 outlook web access 从 python 发送电子邮件

2025年04月02日31oomusou

如果我的工作失败,我需要用 python 发送电子邮件,但是由于公司政策,我只能使用 Outlook Web Access。如何从 python 连接到 Outlook Web Access 以发送电子邮件?

请您参考如下方法:

这不能归功于我,但我可以引导您找到可能的解决方案。

这是链接:http://win32com.goermezer.de/content/view/227/192/ 这是代码

import win32com.client 
 
s = win32com.client.Dispatch("Mapi.Session") 
o = win32com.client.Dispatch("Outlook.Application") 
s.Logon("Outlook2003") 
 
Msg = o.CreateItem(0) 
Msg.To = "recipient@domain.com" 
 
Msg.CC = "more email addresses here" 
Msg.BCC = "more email addresses here" 
 
Msg.Subject = "The subject of you mail" 
Msg.Body = "The main body text of you mail" 
 
attachment1 = "Path to attachment no. 1" 
attachment2 = "Path to attachment no. 2" 
Msg.Attachments.Add(attachment1) 
Msg.Attachments.Add(attachment2) 
 
Msg.Send() 

这很酷,我必须使用它。 可以在此处找到相关的 SO 问题:Python - Send HTML-formatted email via Outlook 2007/2010 and win32com