简体   繁体   中英

How to handle Microsoft outlook app pop-ups using selenium when automating in python

I'm busy automating a process using selenium package in python. My process requires me to send emails using outlook app, but when I try sending emails from python using the code below:

outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'email_address'

mail.Subject = 'Email Subject'
mail.Body = 'Email Body'
attachment = 'Attachment'
mail.Attachments.Add(attachment)

I get this pop-up from outlook: 在此处输入图片说明

Selenium only works for web-based automation, how can I solve this problem using python so that whenever I send an email it automatically clicks on Allow without having to do it manually.

I had a look at my Outlook 2016 Programmatic Access Settings and the Antivirus Status is Invalid: 在此处输入图片说明

You get a standard security prompt produced by Outlook when you access any secured property or just send an item. You can read more about that in the "A program is trying to send an e-mail message on your behalf" warning in Outlook article.

There are several ways to avoid such prompts when you send emails:

  1. Use the Outlook Security Manager which allows turning off and on security prompts at runtime. See Security Manager for the sample code.
  2. Use a low-level API that doesn't trigger security prompts - Extended MAPI or any other wrappers around that API such as Redemption .
  3. Develop a COM add-in that has access to the trusted Application object.
  4. Use group policy objects for setting up machines to not trigger security prompts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM