Dear all,

(Transparency note: This has been posted to 
https://python-forum.io/thread-37103.html before)

The following code will print the ReceivedTime as well as the email body on a 
Win11 machine (pywin32 version 304, personal computer):

   import win32com.client

   outlook = 
win32com.client.GetActiveObject('Outlook.Application').GetNamespace("MAPI")
   inbox = outlook.GetDefaultFolder(6).Items
   messages = list(inbox)

   print(messages[0].ReceivedTime)
   print(messages[0].Body)

On a second machine (Win10, same version of pywin32, company device), execution 
will fail:

   PS C:\Users\xxx> & 
C:/Users/xxx/AppData/Local/Programs/Python/Python310/python.exe 
"c:/Users/xxx/outlook.py"
   2021-05-17 16:47:59.781000+00:00
   Traceback (most recent call last):
     File "c:\Users\xxx\outlook.py", line 8, in <module>
       print(messages[0].Body)
     File 
"C:\Users\xxx\AppData\Local\Programs\Python\Python310\lib\site-packages\win32com\client\dynamic.py",
 line 628, in __getattr__    
       ret = self._oleobj_.Invoke(retEntry.dispid, 0, invoke_type, 1)
   pywintypes.com_error: (-2147467260, 'Operation aborted', None, None)

It can read the ReceivedTime, but not the Body. I think it has to do with 
Outlook security policy as set up on the company device. I've already applied 
the registry keys mentioned at 
https://www.slipstick.com/developer/change-programmatic-access-options/, but 
couldn't see any changed behavior. Also, I can't run Outlook (O365 / V2204) as 
an admin as this will request me to create a new account. I was trying to 
access Trust Center -> Programmatic Access there. Could anybody kindly guide me 
to the correct direction, please?

Best regards,
Timo
_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to