Create Outlook email draft using PowerShell Create Outlook email draft using PowerShell powershell powershell

Create Outlook email draft using PowerShell


Based on the other answers, I have trimmed down the code a bit and use

$ol = New-Object -comObject Outlook.Application$mail = $ol.CreateItem(0)$mail.Subject = "<subject>"$mail.Body = "<body>"$mail.save()$inspector = $mail.GetInspector$inspector.Display()

This removes the unnecessary step of retrieving the mail from the drafts folder. Incidentally, it also removes an error that occurred in Shay Levy's code when two draft emails had the same subject.


$olFolderDrafts = 16$ol = New-Object -comObject Outlook.Application $ns = $ol.GetNameSpace("MAPI")# call the save method yo dave the email in the drafts folder$mail = $ol.CreateItem(0)$null = $Mail.Recipients.Add("XXX@YYY.ZZZ")  $Mail.Subject = "PS1 Script TestMail"  $Mail.Body = "  Test Mail  "$Mail.save()# get it back from drafts and update the body$drafts = $ns.GetDefaultFolder($olFolderDrafts)$draft = $drafts.Items | where {$_.subject -eq 'PS1 Script TestMail'}$draft.body += "`n foo bar"$draft.save()# send the message#$draft.Send()


I think Shay Levy's answer is almost there: the only bit missing is the display of the item.To do this, all you need is to get the relevant inspector object and tell it to display itself, thus:

$inspector = $draft.GetInspector  $inspector.Display()

See the MSDN help on GetInspector for fancier behaviour.