Created
July 15, 2021 17:56
-
-
Save jfrmilner/67a70900156851cd4f15d42c59c625f7 to your computer and use it in GitHub Desktop.
PowerShell script to scan for email errors in Streamserver log files
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
<# | |
PowerShell script to scan for email errors in Streamserver log files | |
Auth: jfrmilner | |
v1 - 2021-06-29 - Initial Release | |
v2 - 2021-07-13 - Change to separate email per log file. Remove file path prefix (now added to email body header). | |
#> | |
$ids = "CH", "AT", "DE", "SE" | |
foreach ($id in $ids) { | |
$path = "C:\StreamServe\domain_$($id)\$($id)_runtime_PROD\export\log\log.txt" | |
$results = Select-String -Pattern "Mail Connector: Failed to send mail\." -Path $path -Context 15, 0 | |
if ($results) { | |
#Build html email | |
$body = $null | ConvertTo-Html -Body "<H2>StreamServe Mail Connector: Failed to send mail ($($path))" | Out-String | |
foreach ($result in $results) { | |
$resultsString = $result.Context.PreContext + $result.Line | |
$body += $resultsString | ForEach-Object { $_ + '<br>' } | |
} | |
#Recipient Addressing | |
switch ($id) { | |
"CH" {$recipients = "[email protected]"} | |
"AT" {$recipients = "[email protected]"} | |
"DE" {$recipients = "[email protected]"} | |
"SE" {$recipients = "[email protected]"} | |
} | |
Send-MailMessage -To $recipients -Subject "StreamServe Mail Connector: Failed to send mail" -BodyAsHtml $body -From "[email protected]" -SmtpServer "SMTPInternal.domain.com" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment