Advertisements

PowerShell:- Create an email using PowerShell

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 = “User1@thexchangelab.com”
$TlabEmail.Subject = “Draft email from PowerShell”
$TlabEmail.Body = “PowerShell makes your life easy”
$TlabEmail.save()

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 = “User1@thexchangelab.com”
$TlabEmail.Subject = “Draft email from PowerShell”
$TlabEmail.Body = “PowerShell makes your life easy”
$TlabEmail.save()
$inspector = $TlabEmail.GetInspector
$inspector.Display()

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

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

Hope it helps.

Advertisements

You may also like...

Leave a Reply