Google Reviews
If you find this content or our services useful, please leave us a review.

I often write administrative scripts and am required to send an email using PowerShell.  There are a couple of ways to do this depending on our objectives.  If we just require an email then I opt to use the Send-MailMessage PowerShell cmdlet.  However if the email requires voting buttons, we can also utilise the Outlook.Application com object.

Send an Email Using PowerShell and Send-MailMessage

$MailMessage = @{ 
    To = "Example <>"
    Bcc = "Example1 <>", "Example2 <>"
    From = "Example3 <>"
    Subject = "Example Subject" 
    Body = "This is an <b>example</b> HTML email." 
    Smtpserver = "" 
    Port = 25    
    UseSsl = $false
    BodyAsHtml = $true
    ErrorAction = "Stop" 

Send-MailMessage @MailMessage

Send an Email Using PowerShell and Outlook.Application with Voting

An advantage of using Outlook.Application is that we don’t need to specify a ‘To’ address if we just want to Bcc multiple recipients.  With Send-MailMessage, the ‘To’ field is mandatory.

$outlookComObject = New-Object -ComObject Outlook.Application
$NewMail = $outlookComObject.CreateItem(0)
$NewMail.Subject = "Example Subject"
$HTMLBody = "This is an <b>example</b> HTML email."
$NewMail.HTMLBody = $HTMLBody
#You will need the relevant permissions to send on behalf of
#$NewMail.SentOnBehalfOfName = "Example <>"
$NewMail.To = "Example1 <>"
$newmail.Bcc = "Example2 <>;Example3 <>" 
Send an Email Using PowerShell
Comments have now been disabled. If you have a question to ask about this post please ask the community!