Skip to content

Instantly share code, notes, and snippets.

@jfrmilner
Created July 15, 2021 17:56
Show Gist options
  • Save jfrmilner/67a70900156851cd4f15d42c59c625f7 to your computer and use it in GitHub Desktop.
Save jfrmilner/67a70900156851cd4f15d42c59c625f7 to your computer and use it in GitHub Desktop.
PowerShell script to scan for email errors in Streamserver log files
<#
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 = "firstname.lastname@domain.com"}
"AT" {$recipients = "firstname.lastname@domain.com"}
"DE" {$recipients = "firstname.lastname@domain.com"}
"SE" {$recipients = "firstname.lastname@domain.com"}
}
Send-MailMessage -To $recipients -Subject "StreamServe Mail Connector: Failed to send mail" -BodyAsHtml $body -From "StreamServe-noreply@domain.com" -SmtpServer "SMTPInternal.domain.com"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment