4

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?

mmmtoasted
  • 103
  • 1
  • 5
  • check these links :[http://stackoverflow.com/questions/6332577/send-outlook-email-via-python](http://stackoverflow.com/questions/6332577/send-outlook-email-via-python) [http://www.holovaty.com/writing/python-outlook-web-access/](http://www.holovaty.com/writing/python-outlook-web-access/) – Vaibhav Jul 20 '16 at 16:54
  • did you solve thi problem? I am in the same situation. – Kevin liu Feb 25 '22 at 05:28

1 Answers1

2

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

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

Community
  • 1
  • 1
Quentin
  • 700
  • 4
  • 10