Link to home
Start Free TrialLog in
Avatar of Cristal638
Cristal638

asked on

(500 pts.) Use Outlook 2003 to trigger an event

Hello all,
This might be an easy 500 pts. for you.  I just need it right away.  FYI - MS Outlook 2003 on Windows XP Pro.  Anyway, here's what I'm looking to do:
Everyday I receive an automatic email notification letting me know that my files are ready.  Each email has the same exact sender, subject and verbiage.  The only difference is the time it's received.  I want to be able to automatically run a batch file as soon that email is received.  Is this possible and if so, how?

Thanks,
Dave
Avatar of David Lee
David Lee
Flag of United States of America image

Hi Cristal638,

It is possible via a bit of scripting.  The script watches for a message with specific characteristics, e.g. the ones you described above, and then use a shell object to launch the batch file.  For this to work Outlook has to be open and running.  It will not work otherwise.  I can provide the script if you're interested.

Cheers!
Avatar of Cristal638
Cristal638

ASKER

Can this be done in VBA code.  If so could you send a sample that looks for an email with the subject line of "This is a test" and then runs a batch file called c:\test.bat

Thanks,
Dave
In the VBA window, in Module ThisOutlookSession

there is the event handler  Application_NewMail

this is called whenever u get new mail

so u can check this and do your action

but first you must initialise some variables

eg.

Dim olNS As NameSpace, olF As MAPIFolder, olMail As Object

Private Sub Application_Startup()
     Set olNS = Application.GetNamespace("MAPI")
     Set olF = olNS.GetDefaultFolder(olFolderInbox)
End Sub

Private Sub Application_NewMail()
     Set olMail = olF.Items(1)
     MsgBox "Mail Received from " & olMail.SenderName
End Sub

now u can check olMail and do whatever u want


ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial