mhammond / pywin32

Python for Windows (pywin32) Extensions
5.06k stars 798 forks source link

Making Outlook appointments/meetings no longer works #1477

Open rzoun opened 4 years ago

rzoun commented 4 years ago

The code below, for making a meeting with Outlook 2016 in Windows 10, results in an error. The code did work before, but that was with Outlook 2010 in Windows 7. I am using 64-bit version for everything. Have tried Python 3.6.8, 3.7 and 3.8.1 with the same result.

import win32com.client as win32
import datetime

today = datetime.datetime.now()

meetingDate = today
meetingTime = '16:00'
t = meetingDate.strftime("%Y-%m-%d") + ' ' + meetingTime
oOutlook = win32.Dispatch("Outlook.Application")
meeting  = oOutlook.CreateItem(1)       
meeting.Start    =  t
meeting.Subject  = 'Appointment'
meeting.Duration = 30
meeting.Location = 'Lab'
meeting.Body = "Testing"
meeting.MeetingStatus = 1               
meeting.Recipients.Add("name@name.nl")
meeting.Save()
meeting.Send()

I get the error at the line with meeting.Recipients.Add("name@name.nl") (but then using a valid email address). It reads:

File "C:\Program Files\Python37\lib\site-packages\win32com\client\dynamic.py", line 516, in __getattr__
ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2147467260, 'Operation aborted', None, None)
mhammond commented 4 years ago

It might be that you have lost makepy support - try using win32com.client.EnsureDispatch(). If that still doesn't work, try a 32bit python/pywin32

rzoun commented 4 years ago

Thanks for your reply, Mark. Assuming you meant win32com.client.gencache.EnsureDispatch(): tried it but I get the same error. Also tried 32-bit versions of Python 3.7.6 with pywin32: same error.

cstarbird commented 3 years ago

@rzoun Did you ever find a solution to this? I'm trying to parse some outlook msg files and running into the exact same error code. Running Python 3.6, pywin32 228. Thanks!

rzoun commented 3 years ago

@cstarbird No I never found a proper solution. I eventually used a work-around. My goal was to send an Outlook meeting invitation to my colleagues directly using Python. I now do that by using Python to create an .ics file according to specs, and then have Python open that .ics file (with os.startfile()). This just opens the meeting invitation with Outlook on my system, which I can then manually send. So, it's an extra step for me, but it gets the job done.

JGaardDK commented 3 years ago

I have the excact same problem. may it be due to OS/Office version (bits)?

LazyPanda5441 commented 3 months ago

Solution: meeting.RequiredAttendees="abc@abc.com"

https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop.outlook.appointmentitem?view=outlook-pia