Script to alert if no email has arrived...

Hi there,

Have a bit of a left field request, I need to monitor a mailbox and if no emails has arrived within say 1 hour (that is no email at all), then an alert is sent to another email address?

Is this going to be easy to do?  The mailbox's are on an exchange 2010 server if that helps :)...

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

For now, I can only think of some VBA code that monitors to main mailbox every now and then.
That needs a PC to be constantly on and has Outlook installed. Is that a workable solution for you?
For now, I don't see how to do this server side on the Exchange server (similar to a server side mailbox rule, which works without the need of a client to be running)
Jamie786Author Commented:
this can be run on a server of any kind really so yes its an option...
This is a vbscript (save as scriptname.vbs) and can be run as a scheduled job:

Dim myolApp 
Dim myNamespace
Set myolApp = CreateObject("Outlook.Application")
Set myNamespace = myolApp.GetNamespace("MAPI")
Set folder = myNamespace.Pickfolder()
Set folderitems = folder.Items

checkdate  = DateAdd("h", -1, now())

count = 0

for each item in folderitems
	 dateStr = item.SentOn
	 if dateStr >  checkdate then
		count = 1
	 end if

if count = 1 then
	'newer found in past hour
	'no newer mails found
	SendMail "towho", ""
end if

Sub SendMail(TheName, TheAddress) 
Dim objMessage, Rcpt 

Rcpt = Chr(34) & TheName & Chr(34) & "<" & TheAddress & ">" 
Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "No new emails in the past hour received" 
objMessage.From = """email alert"" <>" 
objMessage.To = Rcpt 
objMessage.HTMLBody = "No new emails in the past hour received" 

objMessage.AddAttachment strFilePath

objMessage.Configuration.Fields.Item("") = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item("") = ""

'Server port (typically 25)
objMessage.Configuration.Fields.Item("") = 25 



End Sub

Open in new window

Obviously, some strings need to be changed to fit what you want, email address and smtp server also.
Depends on Outlook being installed, the correct profile loading. Depends also on CDO the be working on the server.
Set folder = myNamespace.Pickfolder() also needs to be fixed to the correct folder in the form of
Set folder = myNamespace.Folders("mailboxname").Folders("inbox")
Works best in Exchange/Outlook environment, but also POP3 if auto retrieve has been set (just don't run the script only once per hour, since it might needs to retrieve messages that are only "seen" during the next run)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Jamie786Author Commented:
Should the set folders be set like this :-

Set folder = myNamespace.Pickfolder("voicemailbox").Folders("inbox") ("voicemailfolder")
Set folderitems = folder.Items

So inside a mailbox called voicemailbox and inside a folder that is nested below the inbox is a folder called voicemailfolder.  Or have I totally got the syntax wrong :)
The syntax is:

Set folder = myNamespace.Folders("voicemailbox").Folders("inbox").Folders("voicemailfolder")

Open in new window

Please note, the first folder isn't really a folder, it's the name of the most top level entry (in folder view, minimize as many top folders as you can, you will end up with this name, this is the only top row that can't be minimized)
Jamie786Author Commented:
perfect that seems to work fine.. many thanks for that!
Jamie786Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Email Clients

From novice to tech pro — start learning today.