question

KevinBuchs-8805 avatar image
0 Votes"
KevinBuchs-8805 asked KevinBuchs-8805 answered

How can I configure Windows Server 2019 to email system notifications

I've never done this on any Windows Server version previously. So, I found this https://docs.microsoft.com/en-us/windows-server/storage/fsrm/configure-email-notifications . Seems easy enough, but, alas, is not supported on Windows Server 2019 (I guess because I am not configuring a File Server). I've got a remote SMTP server (everything on AWS) and just want the quick and dirty configuration. This is the only Windows server I manage, so I am not interested in any high overhead tools like System Center, etc. Thanks!

windows-serverwindows-server-2019
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
1 Vote"
DSPatrick answered KevinBuchs-8805 commented

You can follow along here to set that up.
https://www.ryadel.com/en/event-viewer-send-notification-e-mail-messages-with-powershell/

--please don't forget to upvote and Accept as answer if the reply is helpful--



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@DSPatrick - thanks so much for your reply. I see the basic flow and it all makes sense. However, Send-MailMessage in PowerShell does not look to be up to working with AWS SES - need TLS and user credentials (not Windows PSCredentials). Maybe there is an easy drop-in replacement for it.

0 Votes 0 ·
DSPatrick avatar image
0 Votes"
DSPatrick answered KevinBuchs-8805 commented

Maybe AWS provides notifications for their virtual machines health.

--please don't forget to upvote and Accept as answer if the reply is helpful--





· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

They do provide notifications for their VMs and other resources health. However, it is Windows OS notifications that I am interested in. Same issue on Azure.

0 Votes 0 ·

Hi

This link may bring some help o solve your problem:
STEP-BY-STEP: HOW TO TRIGGER AN EMAIL ALERT WHEN A SPECIFIC WINDOWS SERVICE STARTS OR STOPS ON WINDOWS SERVER 2016
https://clusteringformeremortals.com/2018/10/29/step-by-step-how-to-trigger-an-email-alert-when-a-windows-service-starts-or-stops-on-windows-server-2016/

Please note: Information posted in the given link is hosted by a third party. Microsoft does not guarantee the accuracy and effectiveness of information.
Best Regards


0 Votes 0 ·

This was the working solution for sending email. Details in my answer below.

0 Votes 0 ·
hdsouza avatar image
1 Vote"
hdsouza answered

If Send-MailMessage is a problem try "[System.Web.Mail.SmtpMail]::Send($mail)"

Here is a script I wrote using the above command to send email using Gmail

 $SendingServer = "smtp.gmail.com"
 $FromAddress = "a1@gmail.com"
 $ToAddress = "a1@gmail.com"
 $SmtpPort = "465"
    
 $GmailPass = Get-Content "c:\agmail.txt" | ConvertTo-SecureString
 $Cred_Gmail = New-Object System.Management.Automation.PsCredential($FromAddress,$GmailPass)
    
       $subject = "checking the connection" 
       $body = "this is awesome" 
    
    
     # Create a new mail with the appropriate server settigns
 [System.Reflection.Assembly]::LoadWithPartialName("System.Web") > $null
     $mail = New-Object System.Web.Mail.MailMessage
     $mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver", $SendingServer)
     $mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", $SmtpPort)
     $mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpaccountname", $FromAddress)
     $mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpemailaddress", $FromAddress)
     $mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1)
     $mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", $FromAddress)
     $mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", $Cred_Gmail.GetNetworkCredential().password)
     $mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", $true)
     $mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2)
     $mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 20)
    
     # Set up the mail message fields
     $mail.From = $FromAddress
     $mail.To = $ToAddress
     $mail.Subject = $subject
     $mail.Body = $body
    
 [System.Web.Mail.SmtpMail]::Send($mail)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
0 Votes"
DSPatrick answered KevinBuchs-8805 commented

Maybe the task can call a vbscript using CDO.Message
https://social.technet.microsoft.com/wiki/contents/articles/54007.vbscript-send-email-with-attachment.aspx

--please don't forget to upvote and Accept as answer if the reply is helpful--





· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Seems CDO is abandoned. I can't find any documentation on the schema for authentication types. I'm sure AWS SES does not use Basic Auth as the example shows.

0 Votes 0 ·
DSPatrick avatar image
0 Votes"
DSPatrick answered

Just checking if there's any progress or updates?

--please don't forget to upvote and Accept as answer if the reply is helpful--



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

KevinBuchs-8805 avatar image
0 Votes"
KevinBuchs-8805 answered

I finally got a chance to spend another hour on this today. I did get proper email sending working. So, I started with @DSPatrick pointer:

You can follow along here to set that up.
https://www.ryadel.com/en/event-viewer-send-notification-e-mail-messages-with-powershell/

Then I combined that with the pointer from @Miles-MSFT to https://clusteringformeremortals.com/2018/10/29/step-by-step-how-to-trigger-an-email-alert-when-a-windows-service-starts-or-stops-on-windows-server-2016/ .

Here is my script thus far:

 # -------------------------------------
 # Ryadel.com - Powershell script to send an e-mail through the Event Viewer
 # -------------------------------------
 #
 # To test this script you can use Powershell to write your own test error log entry in the following way:
 # -------------------------------------
 # New-EventLog –LogName Application –Source "Test"
 # Write-EventLog –LogName Application –Source "Test" –EntryType Error –EventID 1 –Message "This is a test message."
 param([String]$log)
    
 $event = get-eventlog -LogName $log -newest 1
 #get-help get-eventlog will show there are a handful of other options available for selecting the log entry you want.
 #example: -source "your-source"
    
 # "Error" - send only error
 if ($event.EntryType -eq "Error")
 {
     $PCName = $env:COMPUTERNAME
     $EmailBody = $event | format-list -property * | out-string
     $EmailFrom = "$PCName <sesemail@example.com>"
     $EmailTo = "sesemail@example.com" 
     $EmailSubject = "[win-ansys] Windows Error Event Log [Application]"
     $SMTPServer = "email-smtp.us-east-1.amazonaws.com"
     $un="** redacted SES username **"
     $pw="** redacted SES password **"
     $SMTPClient.Credentials = New-Object System.Net.NetworkCredential($un, $pw)
     $SMTPClient.EnableSsl = $true
     Write-host "Sending Email"
     $SMTPClient.Send($EmailFrom, $EmailTo, $EmailSubject, $EmailBody)
     Write-host $event
 } else {
     write-host "No error found"
     write-host "Here is the log entry that was inspected:"
     $event
 } 

This works when run from the command line, after running the Write-EventLog example up near the top in comments.

Following the document on ryadel.com (link above) for creating an attached task in Event viewer for a specific log hardcoded (i.e. omit the $log parameter, hard code "Application") does not work. Even manually triggering that scheduled task results in some sort of error (the RDP screen flashes a blank window momentarily). I don't know how to debug that.

With the code above, I was attempting to parameterize the event viewer log used because it appeared I was going to have to manually create a task for each individual log. Sure wish there was a catch all.

So, 1:20 spent today on this. That is all I can afford for a week, at least.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.