'Suppressing Outlook "This program is trying to access E-mail" pop-up for specific powershell script only

When I run the following powershell script to send an e-mail :

$Outlook = New-Object -ComObject Outlook.Application
$file = Get-ChildItem -Path "H:\TP65655\IDX CVA\UAT" -Include *.idx -Recurse | Where {$_.CreationTime -gt (Get-Date).AddDays(-1)}
$atts = $file.fullname
$Mail = $Outlook.CreateItem(0)
$Mail.To = "[email protected]"
$Mail.Subject = "Testing E-mail Automation"
$Mail.Body = "UAT TEST"
Try
{
    $Mail.Attachments.Add($atts)
    $Mail.Send()
    Write-Host "Mail Sent Successfully"
    Read-Host -Prompt “Press Enter to exit”
}
Catch
{
    Write-Host "File Not Attached Successfully, Please Try Again"
    Read-Host -Prompt “Press Enter to exit”
    Exit
}

The following pops up from Outlook :

Pop Up from Outlook

Is there any way I can remove this without changing the programmatic access in Trust Center to "Never" as this is an organization desktop and that option is not feasible.



Solution 1:[1]

You get a standard security prompt in Outlook. Your options are:

  1. Use the Outlook Security Manager component which allows to disable such warnings at run-time dynamically.
  2. Use a low-level API on which Outlook is based on - Extended MAPI. It doesn't throw security warnings or pop-ups. Or just consider using any wrapper around a low-level API such as Redemption.
  3. Develop a COM add-in which has access to the trusted Application object. COM add-ins don't trigger such security prompts.
  4. Deploy security settings via GPO.
  5. Install any antivirus software with latest updates.

You may find the "A program is trying to send an e-mail message on your behalf" warning in Outlook article in MSDN helpful.

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 Eugene Astafiev