Best way to start a program when specific email received?

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

I have posted this to both the outlook and vb groups because I am not
sure of the best way to approach this.

I have written a VB program that processes an email based on the
customer it is received from, the type of order, etc.

I would like the program to start up whenever an email is received by
the address I have Outlook set to.

Am I better off to wake up my program periodically and check for the
emails?

Or is there a way to just have Outlook call my program when an email
is received?

I know how to save the email to a file or database when it is received
but I am not aware of how to kick off a program from Outlook when an
email is received.

I would appreciate all thoughts and pointers to articles or
discussions. This seems to fall in between the two programs as I am
looking for the best practice.

Thank you in advance for your help.
 
The best and most robust way is to use an Outlook COM addin, which can
handle the ItemAdd event in the Items collection of the Inbox.
 
The best and most robust way is to use an Outlook COM addin, which can
handle the ItemAdd event in the Items collection of the Inbox.

Thank you.

I've done quite a bit of programming, but never used COM.

I will look into that. Do you have a suggestion I might be able to
use more quickly?

Thanks.
 
Do you have a suggestion I might be able to use more quickly?

Depending on which version of Outlook you have, you can setup a mail rule to
run your program on an incomming email to a specified address.
 
Depending on which version of Outlook you have, you can setup a mail rule to
run your program on an incomming email to a specified address.
Outlook 2000, Service Pack 3.

I will take a look at that.

Thanks.
 
You can prototype your code as a macro that runs automatically in the
Outlook VBA. It would be put in the ThisOutlookSession class.

Dim WithEvents colItems As Outlook Items

Private Sub Application_Startup()
Dim oNS As Outlook.NameSpace

Set oNS = Application.GetNameSpace("MAPI")
Set colItems = oNS.GetDefaultFolder(olFolderInbox)
End Sub

Then just select colItems in the left drop-down, ItemAdd in the right
drop-down and the prototype of the event handler will be added to the class.
The next time you start Outlook it will run for every new item (for 15 or
fewer items at a time). Make sure your macro security is set to allow the
macro to run.
 
You can prototype your code as a macro that runs automatically in the
Outlook VBA. It would be put in the ThisOutlookSession class.

Dim WithEvents colItems As Outlook Items

Private Sub Application_Startup()
Dim oNS As Outlook.NameSpace

Set oNS = Application.GetNameSpace("MAPI")
Set colItems = oNS.GetDefaultFolder(olFolderInbox)
End Sub

Then just select colItems in the left drop-down, ItemAdd in the right
drop-down and the prototype of the event handler will be added to the class.
The next time you start Outlook it will run for every new item (for 15 or
fewer items at a time). Make sure your macro security is set to allow the
macro to run.

Thank you.
 
Back
Top