Skip to content
Snippets Groups Projects
Commit 01ac3f7a authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard: Committed by Niko Ehrenfeuchter (adm)
Browse files

Add Send-MailReport().

Refers to #13
parent 0242fa58
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,8 @@ function Exit-IfDirMissing([string]$DirName, [string]$Desc) {
if (Test-Path -PathType Container $DirName) {
Return
}
Write-Host "ERROR: can't find / access $($Desc) path: $($DirName)"
$msg = "ERROR: can't find / access $($Desc) path: $($DirName)"
Send-MailReport -Subject "path or permission error" -Body $msg
Exit
}
......@@ -157,6 +158,33 @@ function Update-ServiceBinaries {
}
function Send-MailReport([string]$Subject, [string]$Body) {
$Subject = "[$($Me)] $($env:COMPUTERNAME) - $($Subject)"
$msg = "------------------------------`n"
$msg += "From: $($EmailFrom)`n"
$msg += "To: $($EmailTo)`n"
$msg += "Subject: $($Subject)`n`n"
$msg += "Body: $($Body)"
$msg += "`n------------------------------`n"
try {
Send-MailMessage `
-SmtpServer $EmailSMTP `
-From $EmailFrom `
-To $EmailTo `
-Body $Body `
-Subject $Subject `
-ErrorAction Stop
Log-Info -Message "Sent Mail Message:`n$($msg)"
}
catch {
$ex = $_.Exception.Message
$msg = "Error sending email!`n`n$($msg)"
$msg += "Exception message: $($ex)"
Log-Error -Message $msg
}
}
function Log-Message([string]$Type, [string]$Message, [int]$Id){
$msg = "[$($Me)] "
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment