Solved

Create a notification when E-Mail is not received.

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

Integrate social media with email signatures

Is your company active on social media? Do you also use email signatures? Including social media icons in your email signature is a great way to get fans for free. Let all your email users know you’re on social media quickly and easily, in a single click.

Join & Write a Comment

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now