1
votes

I use the following approach for sending an email in Outlook.

import pandas as pd
import numpy as np
import win32com.client as win32


df = pd.DataFrame(np.array([[1, 2], [4, 5]]), index=('27-04-2020','28-04-2020'), columns=('Prediction', 'Certainty'))

html= df.to_html()

#SEND MAIL
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = '[email protected]'
mail.HTMLBody = html
mail.Subject = "Test"
mail.send

However, I get an error when running the code: pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'The operation failed.', None, 0, -2147467259), None)

Do any of you have an idea for a solution?

1

1 Answers

0
votes

It seems you are getting a standard security issue in Outlook...

There are several ways for suppressing such issues brought to us by the Outlook object model:

  1. Use a third-party components for supressing Outlook security warnings. See Security Manager for Microsoft Outlook for more information.

  2. Use a low-level API instead of OOM. Or any other third-party wrappers around that API, for example, Redemption.

  3. Develop a COM add-in that has access to the trusted Application object. And then communicate from a standalone application with an add-in using standard .Net tools (Remoting).

  4. Use group policy objects for setting up machines.