| 1 |
"""
|
| 2 |
OutlookLib
|
| 3 |
|
| 4 |
Created by
|
| 5 |
Emanuel Borges
|
| 6 |
03.15.2017
|
| 7 |
|
| 8 |
Just an Outlook library to make automating Outlook a bit faster for me.
|
| 9 |
|
| 10 |
"""
|
| 11 |
|
| 12 |
from win32com.client import constants as c
|
| 13 |
import win32com.client
|
| 14 |
|
| 15 |
class OutlookConnection:
|
| 16 |
def __init__(self):
|
| 17 |
self.outlookApp = win32com.client.Dispatch("Outlook.Application")
|
| 18 |
## you dont have to make instance varibles from constants here. It just looks a bit cleaner.
|
| 19 |
## Before makepy, i had to map right to the 0x0. after makepy you can just ref a constant.
|
| 20 |
#self.outlookEmailItem = 0x0
|
| 21 |
self.outlookEmailItem = c.olMailItem
|
| 22 |
self.outlookAppointmentItem = c.olAppointmentItem
|
| 23 |
self.outlookMeeting = c.olMeeting
|
| 24 |
self.outlookTemplateType = c.olTemplate
|
| 25 |
|
| 26 |
def DraftEmail(self, emailTO, emailCC, emailSubject, emailBody, emailAttachment = None, bodyType = 'HTML', finishType = 'Display', savePath = None):
|
| 27 |
"""Easy way to draft an email and wont send if you allow finishType as Display. Can be changed to OFT, to save it instead."""
|
| 28 |
newEmailMessage = self.outlookApp.CreateItem(self.outlookEmailItem)
|
| 29 |
newEmailMessage.Subject = emailSubject
|
| 30 |
newEmailMessage.GetInspector
|
| 31 |
if bodyType == 'HTML':
|
| 32 |
newEmailMessage.HTMLBody = emailBody
|
| 33 |
else:
|
| 34 |
newEmailMessage.Body = emailBody
|
| 35 |
newEmailMessage.To = emailTO
|
| 36 |
newEmailMessage.CC = emailCC
|
| 37 |
if emailAttachment:
|
| 38 |
newEmailMessage.Attachments.Add(Source=emailAttachment)
|
| 39 |
if finishType == 'OFT':
|
| 40 |
newEmailMessage.SaveAs(savePath)
|
| 41 |
else:
|
| 42 |
newEmailMessage.Display()
|
| 43 |
#newEmailMessage.send()
|
| 44 |
|
| 45 |
def DraftMeetingRequest(self, meetingRequired, meetingOptional, meetingSubject, meetingLocation, meetingBody, bodyType = 'HTML', finishType = 'Display', savePath = None):
|
| 46 |
"""Easy way to draft a meeting request and wont send if you allow finishType as Display. Can be changed to OFT, to save it instead."""
|
| 47 |
newMeetingInvite = self.outlookApp.CreateItem(self.outlookAppointmentItem)
|
| 48 |
newMeetingInvite.MeetingStatus = self.outlookMeeting
|
| 49 |
newMeetingInvite.Subject = meetingSubject
|
| 50 |
newMeetingInvite.Location = meetingLocation
|
| 51 |
#newMeetingInvite.Start = "7/24/2019 1:30:00 PM"
|
| 52 |
#newMeetingInvite.Duration = 90
|
| 53 |
if finishType == 'OFT':
|
| 54 |
newMeetingInvite.SaveAs(savePath, self.outlookTemplateType)
|
| 55 |
else:
|
| 56 |
newMeetingInvite.Display() |