0

I have a powershell script that opens an outlook mail object and attaches a file to it. Whenever it runs Outlook shows a "suspicious activity" dialog where the user has to click on "Allow" or "Deny". I know that this can be turned off in the trust center, but since i'm not an admin this is not possible.

My code looks like this:

$Outlook = [Runtime.Interopservices.Marshal]::GetActiveObject('Outlook.Application')
$Mail = $Outlook.CreateItem(0)
$Mail.Attachments.Add($TmpFile)
$Mail.Display()

I've read the microsoft docs on this issue and ported the relevant code https://learn.microsoft.com/en-us/office/vba/outlook/how-to/security/obtain-and-log-on-to-an-instance-of-outlook (see line 1 of my code) but it doesn't seem to work. Is there a way through code to prevent the dialog from showing, through for example signing in, or am i out of luck?

drouning
  • 385
  • 4
  • 16
  • This warning is presented for security purposes. Trying to circumvent a security measure like that is not something I (and I guess a lot of other people here on SO) are willing to assist with. – bluuf Feb 05 '19 at 13:17
  • Added a clarification. I dont want to circumvent it, just prevent from showing like by signing in or by identifying myself in some way. – drouning Feb 05 '19 at 13:23
  • your first line work only if outlook was active on current session. I you whant to open new you have to perform relevant code present on your example : https://learn.microsoft.com/en-us/office/vba/outlook/how-to/security/obtain-and-log-on-to-an-instance-of-outlook – Sanpas Feb 05 '19 at 14:21
  • Yes, outlook is active and open as the User i want to display the mail as. – drouning Feb 05 '19 at 14:25
  • In this case your code work in my install i didn't understand why you're trying todo . You excepted to adding a popup that prevent the user ? – Sanpas Feb 05 '19 at 14:27
  • I get a popup similar to this (text is slightly different): https://www.msoutlook.info/pictures/outlook-security-warning-send-email-allow-deny-progress-bar.png Edit: If you don't get this dialog, then your trust center options are different/Anti-Virus is active. – drouning Feb 05 '19 at 14:31
  • See https://stackoverflow.com/questions/14898756/how-to-avoid-outlook-security-alert-when-sending-outlook-message-from-vbscript – Dmitry Streblechenko Feb 05 '19 at 14:47
  • Or https://stackoverflow.com/questions/49127940/how-to-stop-outlook-security-message-programatically-a-program-is-trying-to-ac – Dmitry Streblechenko Feb 05 '19 at 14:47

0 Answers0