6 Replies Latest reply on May 11, 2018 8:28 AM by 00shep

    Mailbox monitoring

    choch@roirevolution.com

      Hello,

       

      My organization needs to monitor a specific mailbox in a way that will let us know if there is a message older than 3 hours. If one is older, it should send an email to a distribution group. I have done some research and have not found a simple or efficient way of accomplishing this. Any help would be appreciated.

        • Re: Mailbox monitoring
          osborne_graham

          I wrote a powershell script for my company with a GUI front end that does exactly this, monitoring an external gmail account to make sure it's receiving an email every 15 minutes and sends an email to a DL depending on the time/date the alert occurs. However I've not got around to moving it over to Solarwinds yet. If you don't find any better answer I'll move it up my 'todo' list.

            • Re: Mailbox monitoring
              choch@roirevolution.com

              This sounds close to what I need. I am trying to monitor an internal inbox for unread emails older than 3 hrs. I would not mind seeing your powershell script if you do not mind.

                • Re: Mailbox monitoring
                  osborne_graham

                  My script will only work with gmail accounts as it hooks into the the atom xml of the google mailboxes to get the header - I suppose it could be converted to Exchange emails by pulling the header with get-message.

                  I have another script for exchange emails that looks for unread messages - I'll find that so you can single out just unread ones.

                   

                  Anyway, the guts of my script simply puts the last received time of emails from a particular sender (our outbound test account):

                   

                          $from = $a[$i] | select-object -ExpandProperty author | select name -ExpandProperty name

                          $lastreceived = $a[$i] | select issued -ExpandProperty issued

                   

                  Calculates how many minutes it's been:

                   

                      $times = New-TimeSpan $lastreceived $currenttime;

                       [int]$timedifference = $times.totalminutes;

                       $lastrecformatted = Get-Date $lastreceived -Format 'HH:mm'

                   

                  Then reacts depending on the time difference:

                   

                       if ($timedifference -le 15) {

                       $outputBox1.AppendText("$thisdate - It's been $timedifference minutes since the last received email. `r`n")

                       $confirmeda.text = $timedifference.tostring()

                       $confirmeda.Refresh()    

                  }

                       elseif ($timedifference -gt 15 -and $timedifference -le 30 ) {

                       $outputBox1.AppendText("$thisdate - No test email has been received since $lastrecformatted, $timedifference minutes ago. Confirm by manaully checking the ###### mailbox. `r`n")

                       $confirmeda.text = $timedifference.tostring()

                       $confirmeda.Refresh()

                   

                  Additionally if the user has flagged the email tick box it will also send an email (I also have code to change the recipients depending on the time and day of the week):

                   

                         if ($emailalert.Checked -eq $true) {

                          send-mailmessage -to $recipients1 -from "aaa@aaa.com" -Body "No test email has been received since $lastrecformatted, $timedifference minutes ago. Confirm by manaully checking the ##### mailbox" -subject "Warning" -port "25"

                          }

                          else {

                          $outputBox1.AppendText("Emails are disabled. No email has been sent!")

                          }

                  }

                    • Re: Mailbox monitoring
                      osborne_graham

                      This is what I use to find unread items in an Outlook mailbox (works with either internal or external mailboxes) but does mean the mailbox must be open in outlook for this to work. From here you should be able to pull time/date too:

                       

                      $outlook = New-Object -comobject outlook.application

                      $n = $outlook.GetNamespace("MAPI")

                      $folder = $n.GetDefaultFolder(6)

                      $Folder.Items.Restrict("[UnRead] = True")

                       

                      Sorry, not got much time right now to put all this together but hopefully my last two posts will get you on your way - or atleast give you some ideas.

                • Re: Mailbox monitoring
                  00shep

                  Something like this might be able to help. If you need to target inbox only or something I think you might need to resort to search-mailbox or some other cmdlet. But if they clear the inbox completely this should work. Just replace the user and paste this into a SolarWinds PowerShell component monitor. Then you can set thresholds and alerts based on that component. Good luck.

                   

                  #######################

                   

                  $datefilter1 = (get-date).addhours(-3)

                   

                  $datefilter2 = get-date

                   

                  $user = "user@domain.com"

                   

                  $messagecount = (Get-MessageTrace -RecipientAddress $user -StartDate $datefilter1 -EndDate $datefilter2).count

                   

                  Write-Host 'Statistic: ' $messagecount

                   

                  #######################