如果我的任务失败,我需要使用Python发送电子邮件,但由于公司政策,我只能使用Outlook Web Access。那么如何从Python连接到Outlook Web Access以发送电子邮件呢?
如果我的任务失败,我需要使用Python发送电子邮件,但由于公司政策,我只能使用Outlook Web Access。那么如何从Python连接到Outlook Web Access以发送电子邮件呢?
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 - 通过Outlook 2007/2010和win32com发送HTML格式的电子邮件