Share via


Open new email dialog using powershell

Question

Thursday, February 9, 2017 7:13 AM

Hello,

I'm trying to write a powershell script for opening the new email windows of outlook.

Anyone can help ?

All replies (3)

Thursday, February 9, 2017 7:47 AM

Just create a new mail message and open it.

$message = $folder.Items.Add(0)
$message.Display()

\(ツ)_/


Thursday, February 9, 2017 9:28 AM | 1 vote

You can create a new email with the following code, some settings are optional. 

$ol = New-Object -comObject Outlook.Application

#Create the new email
$mail = $ol.CreateItem(0)

#Optional, set the subject
$mail.Subject = "<subject>"

#Optional, set the body
$mail.Body = "<body>"

#Get the new email object
$inspector = $mail.GetInspector

#Bring the message window to the front
$inspector.Activate()

Thursday, February 9, 2017 9:39 AM

Just for information sake.  "$message.Display()" does the same thing as getting an inspector and activating it.  In all cases the mail item editor is only brought to the front of Outlook but does not make Outlook the active application.

I generally choose the folder and use it to create the item as it is more explicit and can be used to determine where the item is saved if it is not sent.

I guess the choice depends on what else one is planning on doing with the item.

\(ツ)_/