In this article we are doing to perform two demonstrations for creating draft emails in Outlook from PowerShell.

Option 1: Create an email draft however you need to open Outlook to see it.
Option 2: Create an email draft but have the email open for you instead of opening Outlook.

Here is the first set of commands (Option 1):

$Outlook = New-Object -comObject Outlook.Application
$TlabEmail = $Outlook.CreateItem(0)
$TlabEmail.To = “[email protected]
$TlabEmail.Subject = “Draft email from PowerShell”
$TlabEmail.Body = “PowerShell makes your life easy”
$TlabEmail.save()

Powershell:- create an email using powershell

Here is the second set of commands (Option 2) with 2x extra lines at the end:

$Outlook = New-Object -comObject Outlook.Application
$TlabEmail = $Outlook.CreateItem(0)
$TlabEmail.To = “[email protected]
$TlabEmail.Subject = “Draft email from PowerShell”
$TlabEmail.Body = “PowerShell makes your life easy”
$TlabEmail.save()
$inspector = $TlabEmail.GetInspector
$inspector.Display()

Powershell:- create an email using powershell

The last two lines for the inspector is what opens up the Outlook shown below:

Powershell:- create an email using powershell

The lines of code that has the To, Subject and Body info in is what you see above.

Hope it helps.

    wpChatIcon

    Discover more from Everything-PowerShell

    Subscribe now to keep reading and get access to the full archive.

    Continue reading