diff --git a/AutoTx/Resources/Update-AutoTxService.ps1 b/AutoTx/Resources/Update-AutoTxService.ps1 index 482ad824a444fc6745458699a027e29a59af5ac0..68c73fc7f994addc07292284368fe80fb1ace60d 100644 --- a/AutoTx/Resources/Update-AutoTxService.ps1 +++ b/AutoTx/Resources/Update-AutoTxService.ps1 @@ -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 {