We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Fire a script when a mailbox receives a message.

nummagumma2 asked
Medium Priority
Last Modified: 2010-03-06
I'm having problems with a service running on my Exchange Server.  I'd like to be able to have a batch file run when an email is received in a specific mailbox.  When using the Rules Wizard in Outlook it appears as though I could run a script, but it would only work if I had a machine running, Outlook open.  I need something that will run server side.  I've heard about "Event Scripting" but can't seem to find any good write ups with examples.  Can anyone point me in the right direction?
Watch Question

Stacy SpearPresident/Principal Consultant

Event Sinks - http://www.microsoft.com/downloads/details.aspx?familyid=0CD7F344-CAD6-416E-9BC1-0D7C214E1D0B&displaylang=en

Are the way to go. Can be a variety of languages and can be used for all sorts of things.
Stacy SpearPresident/Principal Consultant

I believe somewhere on MSDN (if not in the download) there is an example with code of exactly what you want to do. Off today, so my workstation with the download on it is not available.


darkstar - thanks for posting.  I've read the doc you sent and see that the method is what I want - unfortunately there's no sample code in the download (or anywhere else on MSDN that I can find) that I can tweak to do what I want.  I'm still looking for a good example of a sink that would permit some kind of batch file to be executed...
Stacy SpearPresident/Principal Consultant

Code example - outgoing (easily modifiable to incoming) http://support.microsoft.com/kb/317680 

On arrival code example - http://support.microsoft.com/kb/313404
Stacy SpearPresident/Principal Consultant

Posted too quick. I thought it was on MSDN, but it seems as if all is on support.microsoft. Here is a good bit here.


Glenn's example of using MS sinks (his stuff is great, plus he help write the app) http://gsexdev.blogspot.com/2005/05/c-catchall-onarrival-event-sink.html


Thanks darkstar.  I found those.  I've used the one for outgoing disclaimer message in the past.  Unfortunately, not being a programmer, I'm not savvy enough to tweak either of them to fire when mail is received on only 1 email address, nor am I clear where to tweak to make it so that the code would call my existing batch file... (or how to incorporate my batch into the sink).

The logic is simple enough to me, just not how to code it.

if message arrives on specialaddress@domain.com then fire batch file.

I suppose it would be best if the message had a specific word or phrase in the subject to limit the small possibility of abuse by a spammer...
President/Principal Consultant
Perhaps something along the lines of the following:


Sub IEventIsCacheable_IsCacheable()
      'To implement the interface, and return S_OK implicitly
End Sub

Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
      Dim envFlds
      Dim colAttachs
      Dim iFound
      Set envFlds = Msg.EnvelopeFields

      If Msg.To = "specialaddress@domain.com" and Msg.Subject = "specialsubject" Then
            'perform batch file stuff here (VBS only I think)
            'or maybe call filename.batch
            'do nothing
      End If

End Sub


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Untested, but I'll assume it works.... no time to test and want to award points for effort.

Thanks darkstar.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.