Create Outlook email draft using PowerShell

Viewed 40065

I'm creating a PowerShell script to automate a process at work. This process requires an email to be filled in and sent to someone else. The email will always roughly follow the same sort of template however it will probably never be the same every time so I want to create an email draft in Outlook and open the email window so the extra details can be filled in before sending.

I've done a bit of searching online but all I can find is some code to send email silently. The code is as follows:

$ol = New-Object -comObject Outlook.Application  
$mail = $ol.CreateItem(0)  
$Mail.Recipients.Add("XXX@YYY.ZZZ")  
$Mail.Subject = "PS1 Script TestMail"  
$Mail.Body = "  
Test Mail  
"  
$Mail.Send() 

In short, does anyone have any idea how to create and save a new Outlook email draft and immediately open that draft for editing?

5 Answers

if you want to use HTML template please use HTMLbody instead of Body , please find sample code below:

$ol = New-Object -comObject Outlook.Application
$mail = $ol.CreateItem(0)
$mail.Subject = "Top demand apps-SOURCE CLARIFICATION"
$mail.HTMLBody="<html><head></head><body><b>Joseph</b></body></Html>"
$mail.save()

$inspector = $mail.GetInspector
$inspector.Display()
Related