Last active
August 29, 2015 14:26
-
-
Save kmhuglen/858c4fdc92088fea8046 to your computer and use it in GitHub Desktop.
Example of how to use Send-MailMessage with conditionally CC and BCC arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[string]$MailFrom = "me@domain.com" | |
[array]$MailTo = "you@domain.com", "other@domain.com" | |
[string]$MailSubject = "my subject" | |
[string]$MailBody = @" | |
<b>Heading</b> | |
Some text<br> | |
New Line with more text<br> | |
"@ | |
[string]$MailServer = "smtp.domain.com" | |
[array]$MailCc = "optional@domain.com" # Don't know if this variable is set or not | |
[array]$MailBcc = "optional@domain.com" # Don't know if this variable is set or not | |
$MailArguments = @{ | |
From = $MailFrom | |
To= $MailTo | |
Subject = $MailSubject | |
Body = $MailBody | |
BodyAsHtml = $True | |
SmtpServer = $MailServer | |
Encoding = [System.Text.Encoding]::UTF8 | |
} | |
If($MailCc){$MailArguments.Add("Cc",$MailCc)} | |
If($MailBcc){$MailArguments.Add("Bcc",$MailBcc)} | |
Send-MailMessage @MailArguments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment