Created
May 20, 2012 21:08
-
-
Save elvarb/2759544 to your computer and use it in GitHub Desktop.
Powershell: Send Email
This file contains hidden or 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
param( | |
[string]$From = "[email protected]", | |
$To = "[email protected]", | |
[string]$Priority = "High", | |
[string]$SMTPServer = "smtp.domain.com", | |
$Encoding = [System.Text.Encoding]::UTF8, | |
[string]$Subject = $(throw "Argument and value for '-Subject' is required."), | |
[string]$Message = $(throw "Argument and value for '-Message' is required."), | |
[string]$Attachments = "No" | |
) | |
if($Attachments -eq "No") { | |
send-mailmessage ` | |
-From $From ` | |
-To $To ` | |
-Priority $Priority ` | |
-SMTPServer $SMTPServer ` | |
-Subject $Subject ` | |
-Encoding $Encoding ` | |
-BodyAsHTML ` | |
-Body $Message | |
} else { | |
send-mailmessage ` | |
-From $From ` | |
-To $To ` | |
-Priority $Priority ` | |
-SMTPServer $SMTPServer ` | |
-Subject $Subject ` | |
-Encoding $Encoding ` | |
-BodyAsHTML ` | |
-Body $Message ` | |
-Attachments $Attachments | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment