'Python: Automatically send Outlook email bypassing the programmatic access warning
I am trying to send out email alerts on my virtual machine using Python. This is my code:
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "subject"
newMail.Body = "body"
newMail.To = "me.com"
newMail.display()
newMail.send()
I tried to use newMail.send() but my Outlook send the warning which beats the point of automating these alerts. Also, I can't turn off my outlook because 'Windows could not find an antivirus signature' on my machine.
So I tried to use Alt+S after newMail.display() but had trouble because the new e-mail wasn't always in focus.
I then used SetForegroundWindow to ensure that it was in focus but then started getting pywintypes.error: (0, 'SetForegroundWindow', 'No error message is available') another SO post suggested that sending keys first and then SettingForegroundWindow fixes the issue and it did work for me.
Now however, every time I close the virtual machine window (not log-off) or it gets locked due to inactivity, even though the rest of the script runs in the background, I get pywintypes.error: (5, 'SetForegroundWindow', 'Access is denied') when the email alert is triggered
Is there any workaround to being able to send the email alerts in the background bypassing all these issues?
Thanks,
Sid
Solution 1:[1]
Since you have no control over the anti-virus, you should look at one of the many options discussed at Change Outlook's Programmatic Access Options. Extended MAPI is just one of many options, which one works if any will depend on many other details of your system.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |