Skip to content

Instantly share code, notes, and snippets.

@ploegert
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save ploegert/9898974 to your computer and use it in GitHub Desktop.

Select an option

Save ploegert/9898974 to your computer and use it in GitHub Desktop.
#==============================================================================
# SEND EMAILS Helper
#==============================================================================
function SendEmailAlert()
{
PROCESS
{
write-host "`nSending Email to Notification List with subject of: $EmailSubject`n" -foregroundcolor yellow
$smtpServer = "SERVER"
$emailFrom = "justin.j.ploegert@jci.com"
$emailTo = "justin.j.ploegert@jci.com"
$emailsubject = "BAS-API Reboot"
$emailbody = "The BAS-API Service at: $ServiceName, Instance: $InstanceName was just rebooted."
sendEmail $emailFrom $emailTo $emailsubject $emailbody $smtpServer
}
}
#==============================================================================
# SEND EMAILS!!!
#==============================================================================
# Usage
# do_sendemail -emailmesage "Your FCopy is done" -emailsubject "Your FCopy is done" -emailto "4143504764@pm.sprint.com"
# do_sendemail -emailmesage "Your FCopy is done" -emailsubject "Your FCopy is done" -emailto "justin.j.ploegert@jci.com"
#==============================================================================
Function sendemail([string]$emailFrom, [string]$emailTo, [string]$subject,[string]$body,[string]$smtpServer ,[string]$filePath)
{
#initate message
$email = New-Object System.Net.Mail.MailMessage
$email.From = $emailFrom
$email.To.Add($emailTo)
$email.Subject = $subject
$email.Body = $body
# initiate email attachment
#$emailAttach = New-Object System.Net.Mail.Attachment $filePath
#$email.Attachments.Add($emailAttach)
#initiate sending email
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($email)
write-host "Email Sent to $emailTo"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment