Solved

Create a notification when E-Mail is not received.

Posted on 2009-05-19
4
202 Views
Last Modified: 2012-05-07
Hi,
Could you provide some help with creating a power shell script that would generate a notification (by mail possibly) that would provide an alert to the fact that mail was not received at a specific mailbox or group of mailboxes according to a predefined amount of time?
Thanks For your help.
Jason.
0
Comment
Question by:Elad-a
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:peter_field
ID: 24419985
Have a look at:
http://blogs.msdn.com/jmanning/archive/2007/01/25/using-powershell-for-outlook-automation.aspx

I have written some code that you should be able to adapt below.
$outlook = New-Object -ComObject Outlook.Application
$folder = $outlook.Session.GetDefaultFolder(6)
# You can use AddMinutes instead of AddDays if you like. If you want to see what other properties are avaialble for a message uncomment the line below.
#$folder.Items | select -first 1 | fl *
$match = @( $folder.Items | where { $_.CreationTime -ge ([DateTime]::Now).AddDays(-1) -and $_.TaskSubject -eq "Message Subject" } )
 
if ( $match.Count -eq 0 )
{
    # Send alert
    $smtp = New-Object Net.Mail.SmtpClient("your.smtp.server.here")
    $smtp.Send("from@yourdomain.com", "recipient@domain.com", "email hasn't shown up", "better sort out the problem")
}

Open in new window

0
 

Author Comment

by:Elad-a
ID: 24420769
Thats a realy cool solution, but i need to run it on Ms Exchange 2007 where i dont have an outlook installation.
Is tehre a way to do the same with exchange ?
0
 
LVL 4

Accepted Solution

by:
peter_field earned 500 total points
ID: 24427676
There aren't any native Exchange cmdlets that will let you inspect messages in a mailbox. You have a few solutions that I can think of:

1. EWS
2. WebDAV
3. Outlook as above

1. Calling EWS from Powershell can be done, but I'd imagine not trivial. Wait, you might be saved by the EWS managed API that has been recently released. See http://gsexdev.blogspot.com/2009/04/using-ews-managed-api-with-powershell.html, http://blogs.utexas.edu/glenmark/2009/04/17/using-the-ews-managed-api-via-powershell/.

2. I wouldn't recommend this as WebDAV is on its way out, and it's probably harder than EWS anyway.

Hope that helps. If you need me to adapt the code for point 1 let me know, as I'd be interested in playing with it anyway, but don't have time right at the moment (i.e. next 8-10 hours).
0
 

Author Closing Comment

by:Elad-a
ID: 31582891
Thanks
0

Featured Post

What, When and Where - Security Threats from Q1

Join Corey Nachreiner, CTO, and Marc Laliberte, Information Security Threat Analyst, on July 26th as they explore their key findings from the first quarter of 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question