Created
January 29, 2019 20:52
-
-
Save evoelker/69a772194de1e81306260d7edd37157e to your computer and use it in GitHub Desktop.
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
# Function to send email | |
function sendMail | |
{ | |
<# | |
.SYNOPSIS | |
Function to send email to supplied email address. | |
.DESCRIPTION | |
Function takes the provided email address, subject and message, formates an email and sends it to the configured SMTP server. | |
The subject line is optional. | |
The default subject string can be changed if you don't want to supply a subject parameter. | |
.NOTES | |
The following variable need to be set for this function to work correctly: | |
$date = (Get-Date -Format "M-d-yyyy") | |
$starTime = (Get-Date -Format "HH:mm:ss") | |
$smtpServ = "<SMTP Server>" | |
$fromAddr = "<From email address>" | |
.EXAMPLE | |
sendMail -EmailAddress "<To email address" -Subject "<Email subject line>" -Message "<Email message body>" | |
sendMail -EmailAddress "[email protected]" -Subject "Test email" -Message "Test Body: This is a test." | |
#> | |
param ( | |
[Parameter(Mandatory)] | |
[string]$EmailAddress, | |
[Parameter()] | |
[string]$Subject = "Emergency Site Shutdown - $date", # Default value if none is provided. | |
[Parameter(Mandatory)] | |
[string]$Message | |
) | |
# Send email with formated message | |
Send-MailMessage -From $fromAddr -To $EmailAddress -Subject $Subject -Body $Message -SmtpServer $smtpServ -Port $smtpPort | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment