Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
function New-OutlookEmail {
Will open a new Outlook email item and set some properties.
Will open a new Outlook email item and set some properties.
Email will be sign and encrypted.
Will keep the default signature.
Email will not be sent!
If you have a different SMTP server set it here.
Email address to use as "from".
NOTE: Must exists on your Outlook configuration
Email address to use as "to".
Email address to use as "cc".
.PARAMETER EmailSubject
Email Subject.
.PARAMETER EmailHtmlBody
Email message in HTML format.
$OutlookEmailParams = @{
EmailFrom = ""
EmailTo = ""
EmailCC = ""
EmailSubject = "This is an email setup automatically"
EmailHTMLBody = "Everything you need to say goes here"
New-OutlookEmail @OutlookEmailParams
It will open a new Outlook email window and set the properties.
Author: Cláudio Sobral Silva (@ClaudioESSilva)
param (
[string]$EmailSMTPServer = "",
[Parameter(Mandatory, ValueFromPipeline)]
begin {
function Invoke-SetProperty {
# Auxiliar function to set properties. The SendUsingAccount property wouldn't be set in a different way
[__ComObject] $Object,
[String] $Property,
[Void] $Object.GetType().InvokeMember($Property,"SetProperty",$NULL,$Object,$Value)
try {
$Outlook = New-Object -ComObject Outlook.Application -Verbose:$false
catch {
Write-Warning "Could not create Outlook object. Please try again.`r`nError message: $($error[0])"
#Get the MAPI namespace.
$namespace = $Outlook.GetNameSpace("MAPI")
# Log on by using the default profile or existing session (no dialog box).
$namespace.Logon($null, $null, $false, $true);
process {
Write-Verbose "Setting email properties regading team: $group"
# Create new email
$Mail = $Outlook.CreateItem(0)
#Get account object from email addres
$account = $outlook.Session.Accounts.Item($EmailFrom)
#Change Sender mailbox
Invoke-SetProperty -Object $mail -Property "SendUsingAccount" -Value $account
# Get default signature
$signature = $Mail.HtmlBody
# Fill other properties
$Mail.To = $EmailTo
if ($EmailCC) {
$Mail.Cc = $EmailCC
$Mail.Subject = $EmailSubject
$Mail.HtmlBody = $EmailHtmlBody + $signature
#Sign and Encrypt email
$Mail.PropertyAccessor.SetProperty("", 0x03)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment