0

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@domain.com"
$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.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Does this answer your question? [Suppress Outlook pop-up allow access](https://stackoverflow.com/questions/36302096/suppress-outlook-pop-up-allow-access) – Owain Esau May 02 '22 at 09:47
  • @OwainEsau No. Changing the security settings is not feasible according to our organization policy – A coder May 02 '22 at 09:55
  • Why are you using a COM object to send a mail instead of send-mailmessage? – bluuf May 02 '22 at 10:08
  • @bluuf I'm trying to bypass the SMTP procedure to send it using the outlook application itself – A coder May 02 '22 at 10:32

1 Answers1

0

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.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45