03-20-2024, 08:37 AM
Use email alert script below in a file, named sendemail.ps1.
If you want to run it from a regular command prompt or batch file, run it as:
powershell.exe -file C:\myscripts\sendemail.ps1
The command to run the email alert can be configured in the Windows Task Scheduler or Event Viewer, to run triggered by various events in the system.
Hope this helps!
If you want to run it from a regular command prompt or batch file, run it as:
powershell.exe -file C:\myscripts\sendemail.ps1
Code:
$EmailFrom = "from@email.com"
$EmailTo = "to@email.com"
$Subject = "Alert: enter a useful email subject here. Local time is: $(Get-Date)"
$Body = "enter something useful here. time is: $(Get-Date)"
$SMTPServer = "my.smtp.server.address.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, <my smtp port number example 587>)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("my@email.com","<my password>");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)The command to run the email alert can be configured in the Windows Task Scheduler or Event Viewer, to run triggered by various events in the system.
Hope this helps!

