?
Solved

Create a notification when E-Mail is not received.

Posted on 2009-05-19
4
Medium Priority
?
204 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 2000 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

719 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