【发布时间】:2022-12-28 00:50:54
【问题描述】:
I try to get the users emailadress from outlook with python but i allways get this Error:
File "C:\Users\me\Documents\Coding\Python_Projects\TEST\mainLogin.py", line 76, in __init__
self.myAdress = self.outlook.Session.CurrentUser.Address
File "C:\Users\me\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\__init__.py", line 485, in __getattr__
return self._ApplyTypes_(*args) File "C:\Users\me\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\__init__.py", line 478, in _ApplyTypes_
self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args), pywintypes.com_error: (-2147467260, 'Vorgang abgebrochen', None, None)
I try it with this code:
import win32com.client as win32
...
...
self.outlook = win32.gencache.EnsureDispatch('outlook.application')
self.myAdress = self.outlook.Session.CurrentUser.Address
Can anybody tell me, what is wrong here?
【问题讨论】:
-
shouldn't it be uppercase "Outlook.Application"?
-
Is Outlook running at the time of the call? Is either app running with elevated privileges?
-
outlook.Session.Accounts.Item(1).DisplayNameworks for me -
@DmitryStreblechenko It could be that outlook is running, I can't control whether Outlook is running or not because the program I write will use by many people. Evertime the app will started it checks the User Emailadresse for verification. Every user has a specific address and has to check before they can use it. I do this to get sure that the software only can execute in the company.
-
@Robert - I understand that you cannot control the environment, just trying to narrow down the problem. So is it when the error is raised? How about elevated privileges?
标签: python outlook win32com office-automation