Skip to content

Instantly share code, notes, and snippets.

@elvarb
Created May 20, 2012 21:08
Show Gist options
  • Save elvarb/2759544 to your computer and use it in GitHub Desktop.
Save elvarb/2759544 to your computer and use it in GitHub Desktop.
Powershell: Send Email
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