1

I've created a powershell script along this line.

$ol=new-object -comobject outlook.application
$mail=$ol.createitem(0)
$mail.subject=(get-content $subject)
$mail.attachments.add($attachment)
$inspector=$mail.getinspector
$inspector.display()

But now I'm stuck on the following simple issue: How do I get focus on the newly created message? Sometimes it does appear in the foreground, but not always. How do I force it to the foreground?

Community
  • 1
  • 1
Ernst
  • 103
  • 1
  • 3
  • 8

1 Answers1

3

Try using the Inspector.Activate() method instead of MailItem.Display() in order to bring the mail message window to the foreground. Here's a quote from MSDN:

The Display method is supported for explorer and inspector windows for the sake of backward compatibility. To activate an explorer or inspector window, use the Activate method.

So your script should be:

$inspector = $mail.GetInspector
$inspector.Activate()
Enrico Campidoglio
  • 56,676
  • 12
  • 126
  • 154