Emails and Appointments/Meetings with Outlook and Python

If you would like to send Emails or Meetings or even Recurring meeting with Outlook, you could do it easily with Python.
We will use the pywin32 library for that, which is a python extension for Win32 API and provides ability to create and use COM objects.
It will use your Outlook, and you don’t need to authenticate or setup the SMTP.

Setup

Install pywin32 with pip.

1
2
pip install pywin32
pip install pypiwin32

Python Outlook Email example

1
2
3
4
5
6
7
8
9
10
import win32com.client
outlook = win32com.client.Dispatch("Outlook.Application")

def sendEmail():
Msg = outlook.CreateItem(0) # Email
Msg.To = "test@test.com" # you can add multiple emails with the ; as delimiter. E.g. test@test.com; test2@test.com;
Msg.CC = "test@test.com"
Msg.Subject = "Subject"
Msg.Body = "Your text (not html)"
Msg.Send()

Python Outlook Meetings example

1
2
3
4
5
6
7
8
9
10
11
12
def sendMeeting():    
appt = outlook.CreateItem(1) # AppointmentItem
appt.Start = "2018-10-28 10:10" # yyyy-MM-dd hh:mm
appt.Subject = "Subject of the meeting"
appt.Duration = 60 # In minutes (60 Minutes)
appt.Location = "Location Name"
appt.MeetingStatus = 1 # 1 - olMeeting; Changing the appointment to meeting. Only after changing the meeting status recipients can be added

appt.Recipients.Add("test@test.com") # Don't end ; as delimiter

appt.Save()
appt.Send()

Python Outlook Recurring Meetings example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def sendRecurringMeeting():    
appt = outlook.CreateItem(1) # AppointmentItem
appt.Start = "2018-10-28 10:10" # yyyy-MM-dd hh:mm
appt.Subject = "Subject of the meeting"
appt.Duration = 60 # In minutes (60 Minutes)
appt.Location = "Location Name"
appt.MeetingStatus = 1 # 1 - olMeeting; Changing the appointment to meeting. Only after changing the meeting status recipients can be added

appt.Recipients.Add("test@test.com") # Don't end ; as delimiter

# Set Pattern, to recur every day, for the next 5 days
pattern = appt.GetRecurrencePattern()
pattern.RecurrenceType = 0
pattern.Occurrences = "5"

appt.Save()
appt.Send()