ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Tool_Box/OutlookLib.py
Revision: 648
Committed: Thu Dec 12 20:41:30 2019 UTC (6 years, 3 months ago) by nino.borges
Content type: text/x-python
File size: 2547 byte(s)
Log Message:
small changes

File Contents

# User Rev Content
1 nino.borges 632 """
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 nino.borges 648 ## 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 nino.borges 632
26 nino.borges 637 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 nino.borges 632 newEmailMessage = self.outlookApp.CreateItem(self.outlookEmailItem)
29     newEmailMessage.Subject = emailSubject
30     newEmailMessage.GetInspector
31     if bodyType == 'HTML':
32 nino.borges 648 newEmailMessage.HTMLBody = emailBody
33 nino.borges 632 else:
34     newEmailMessage.Body = emailBody
35     newEmailMessage.To = emailTO
36 nino.borges 648 newEmailMessage.CC = emailCC
37 nino.borges 632 if emailAttachment:
38     newEmailMessage.Attachments.Add(Source=emailAttachment)
39 nino.borges 637 if finishType == 'OFT':
40     newEmailMessage.SaveAs(savePath)
41     else:
42     newEmailMessage.Display()
43 nino.borges 648 #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()