How do I fix an error while trying to send email using Outlook with COM?

43 Views Asked by At

I'm new to the world of programming, I've been following tutorials and recently I have a project to send a report by email but it gives an error, the error follows:

Traceback (most recent call last):
  File "C:\Users\bruno\PycharmProjects\ProjetoPython\pythonProject\venv\Lib\site-packages\win32com\client\dynamic.py", line 84, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pywintypes.com_error: (-2147221005, 'Cadeia de cadeia inválida', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\bruno\PycharmProjects\ProjetoPython\pythonProject\MeuArquivo.py", line 30, in <module>
    outlook = win32.Dispatch("outlook.application")
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bruno\PycharmProjects\ProjetoPython\pythonProject\venv\Lib\site-packages\win32com\client\__init__.py", line 118, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch, userName, clsctx)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bruno\PycharmProjects\ProjetoPython\pythonProject\venv\Lib\site-packages\win32com\client\dynamic.py", line 104, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bruno\PycharmProjects\ProjetoPython\pythonProject\venv\Lib\site-packages\win32com\client\dynamic.py", line 86, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
pywintypes.com_error: (-2147221005, 'Cadeia de cadeia inválida', None, None)

I've already tried sending an email through gmail but the error occurs too. How can I correct the error? Could it be the outlook configuration, such as pop and imap?

1

There are 1 best solutions below

0
Dmitry Streblechenko On

-2147221005 is CO_E_CLASSSTRING, which means there is no COM server with that class name ("outlook.application"). Most likely because Outlook (the real desktop version) is not installed.