Last year I wrote this article that described how you could use a combination of MailStore email archiver’s auditing features, the Windows task manager and a PowerShell script to send you email alerts in the event an archiving job failed.
This worked well but it was a little on the keen side, occasionally being triggered by a job failing that would actually just go on to run fine again shortly afterwards.
A new and improved script
Below you’ll see an improved version of the script which I’ve tweaked to only alert when there have been three consecutive errors with no more than 30 minutes between them.
Mailstore jobs often only take a few minutes to run and usually repeat every 5 minutes, so I’m quite happy that if a job fails more than 3 times in a row it triggers the email alert.
The script is easy to edit though so if you need to wait a little longer, or wish to trigger after more or less consecutive errors, it’s easy enough to change.
While I was reworking the script I also added more information to the email report so you can now see which specific job is failing and how long the job is taking to run. All useful information to know before having to remote into the MailStore Server to take a better look.
Using the script is the same as before so if you haven’t read my previous post yet please read that post here first.
To use the new version simply replace the script with the version below.
Instructions on use
You can download the full ‘mailstore-errors’ script here.
Before you run the script you should first edit the top section as required.
# Alter variables below as required
$path = “c:\scripts\” The location to store temporary files
$trigger = 3 The number of consecutive errors that trigger the email
$timeout = 30 The number of minutes between errors before the counter is reset to Zero
$sender =”email@example.com” ‘From’ address of the email
$recipient=”firstname.lastname@example.org” Who should receive the email
$subject = “MailStore Error” The subject of the email
$smtp_server=”mail.mycompany.com” A valid SMTP server
# Do not alter anything bellow this line ——————————-
If you want to test the alerts work you need to first generate a Mailstore error. The easiest way I have found to do this is to edit one of your MailStore jobs and change the server name to make it invalid. Then run the job manually to generate the error.
Don’t forget to change the job settings back if you do this!
Once you have an error logged into the Windows event log, it’s a simple case to open the PowerShell file within the Powershell editor and run the script 3 times to monitor the trigger level and check it triggers an email.
I have been running this new version of the script for a few weeks now and it’s only alerted me when a job was failing consecutively due to an authentication issue, which helped me spot the issue before it became a real problem.
I hope you find that’s helpful – please leave questions and comments below if you have any!