mmmtoasted
mmmtoasted

Reputation: 103

How do I send an email from python using outlook web access?

I need to send an email in python if my job fails, however due to company polices, I am only allowed to use the Outlook Web Access. How can I connect to Outlook Web Access from python to send an email?

Upvotes: 4

Views: 6655

Answers (1)

Quentin
Quentin

Reputation: 700

I can't take credit for this but I can lead you to a possible solution.

Here's the link: http://win32com.goermezer.de/content/view/227/192/ Here's the code

import win32com.client

s = win32com.client.Dispatch("Mapi.Session")
o = win32com.client.Dispatch("Outlook.Application")
s.Logon("Outlook2003")

Msg = o.CreateItem(0)
Msg.To = "[email protected]"

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()

This is cool and I have to use it. A related SO question can be found here: Python - Send HTML-formatted email via Outlook 2007/2010 and win32com

Upvotes: 2

Related Questions