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
Solved

Create a notification when E-Mail is not received.

Posted on 2009-05-19
4
198 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
  • 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn how to dynamically set the form action using jQuery.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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