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 :)...

Thanks
James
Jamie786Asked:
Who is Participating?
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.

KimputerCommented:
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)
0
Jamie786Author Commented:
this can be run on a server of any kind really so yes its an option...
0
KimputerCommented:
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
next

if count = 1 then
	'newer found in past hour
else
	'no newer mails found
	SendMail "towho", "email@address.com"
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"" <alert@mail.com>" 
objMessage.To = Rcpt 
objMessage.HTMLBody = "No new emails in the past hour received" 

objMessage.AddAttachment strFilePath

objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.com"

'Server port (typically 25)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

objMessage.Configuration.Fields.Update

objMessage.Send 

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)
0

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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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 :)
0
KimputerCommented:
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)
0
Jamie786Author Commented:
perfect that seems to work fine.. many thanks for that!
0
Jamie786Author Commented:
perfect!
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.