Handle Outlook Send Event in Python

1.3k views Asked by At

I am attempting to use the following Python code to send an email through an outlook server however I get a pop up indicating "A program is trying to send an e-mail message on your behalf.

If this is unexpected, click Deny and verify your antivirus software is up-to-date." I know that this can be disabled in outlook settings however I am unable to as I do not have administrator access.

My question I there any way to programmatically handle/avoid this through python? I am also aware this can be avoiding by using smtplib however I am unable to connect to my server through that so it is also not a solution.

import win32com.client
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "Test Subject"
newMail.Body = "Test Body"
newMail.To = "[email protected]"
newMail.Send()
2

There are 2 answers

0
Dmitry Streblechenko On

This feature cannot be disabled by an end-user. The prompt will be displayed if you have an up-to-date anti-virus app on your system. If you cannot control the user environment, you options are listed at http://www.outlookcode.com/article.aspx?id=52

Essentially in PHP you are limited to either Redemption (I am its author), Outlook Security Manager, or ClickYes.

0
Eugene Astafiev On

You get a standard security prompt when calling unsafe functions from the Outlook object model. A low-level API (Extended MAPI) on which Outlook is built doesn't generate such prompts. The Redemption library is built on that API as well. So, you'll need to use Redemption's objects instead of OOM (existing code).

To preserve the existing code you need to use the Outlook security manager component which is designed exactly for such tasks and doesn't require changing or rewriting an existing code.

The ClickYes component allows to click the button on the Security dialog programmatically which I don't think is the best way to go. A window can be overlapped with another applications.