locked
Powershell sendkey in popup in Outlook mail RRS feed

  • Question

  • Hi Experts

    I am creating a script that forwards mails in Outlook with a specific subject. That part is working fine however when sending a mail there is a 3rd party add-in (Titus Message Classification) in Outlook that prompts for mail classification. In this case the default value shall always be used and either clicking OK or pressing Enter will confirm the classification and send the mail.

    The 3rd party add-on popup does not have it's own window but if I select the new mail message window I use SendKeys by running the following code part:

    $wShell = New-Object -ComObject wscript.shell
    $wShell.AppActivate("My mail message subject - Message (HTML)"
    sleep 1
    $wShell.SendKeys("~")

    But when I incorporate the above code snip in my script where I declare a new Outlook, looping through the Inbox mail items and forward the mails the SendKey is not processed before the Titus Message Classification popup is closed, e.g. by clicking Cancel - then the Enter key is pressed within the mail message instead.

    foreach ($mail in $myInbox.Items) {
    
         if ($mail.Subject -eq 'My subject') {
    
               $newMail = $mail.Forward()
               $newMail.Recipient.Add('recipient@contoso.com')
               $newMail.Display()
               $newMail.Send()
    
               $wShell = New-Object -ComObject wscript.shell
               $wShell.AppActivate('My subject - Message (HTML)')
               sleep 1
               $wShell.SendKeys("~")
    
         }
    
    }

    Any ideas?

    • Moved by Bill_Stewart Wednesday, December 12, 2018 8:22 PM This is not "debug/fix/rewrite my script for me" forum
    Friday, August 31, 2018 8:59 AM