0

I'm following a video on youtube on creating a new mail with python. But I'm getting error. Am I missing something? My goal is to create a new mail and insert images from a folder into it. The first and second lines are executed successfully. How can I fix this?

 My code is below:

 import win32com.client as win32
 from win32com.client import Dispatch
 o1App = win32.Dispatch('Outlook.Application')
 o1NS = o1App.GetNameSpace('MAPI')

 Error:

 com_error                                 Traceback (most recent call last)
 C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py in                        _GetGoodDispatch(IDispatch, clsctx)
      88                 try:
 ---> 89                         IDispatch = pythoncom.connect(IDispatch)
      90                 except pythoncom.ole_error:

 com_error: (-2147221005, 'Invalid class string', None, None)

 During handling of the above exception, another exception occurred:

 com_error                                 Traceback (most recent call last)
 <ipython-input-13-a706b9d3cc9d> in <module>
 ----> 1 o1App = win32.Dispatch('Outlook.Application')
       2 o1NS = o1App.GetNameSpace('MAPI')

 C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\__init__.py in      Dispatch(dispatch, userName, resultCLSID, typeinfo, UnicodeToString, clsctx)
      93   """
      94   assert UnicodeToString is None, "this is deprecated and will go away"
 ---> 95   dispatch, userName =         dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
 96   return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo, clsctx=clsctx)
 97 

 C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatchAndUserName(IDispatch, userName, clsctx)
    112         else:
    113                 userName = str(userName)
--> 114         return (_GetGoodDispatch(IDispatch, clsctx), userName)
    115 
    116 def _GetDescInvokeType(entry, invoke_type):

 C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py in _GetGoodDispatch(IDispatch, clsctx)
    89                         IDispatch = pythoncom.connect(IDispatch)
    90                 except pythoncom.ole_error:
---> 91                         IDispatch = pythoncom.CoCreateInstance(IDispatch, None,   clsctx, pythoncom.IID_IDispatch)
    92         else:
    93                 # may already be a wrapped class.

com_error: (-2147221005, 'Invalid class string', None, None)
1

1 Answer 1

0

The error means the desktop version of Outlook is not installed. Keep in mind that the desktop version of Outlook is completely unrelated to the new web-based Outlook (aka Monarch). The New Outlook does not provide any programmatic access.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.