Monitor Outlook Mailbox for new e-mail and process e-mail in VB.Net Application

R

Roger

I am creating an application that will sit on a client pc and monitor the
inbox. When an e-mail enters the inbox, then an even will be fired and I
will then be able to process the mail.

I have the following code that does fire the eventhandlerNewMail,
but I don't know how to do the following 2 things...

1. Get the NewMail object so I can look at the mailitems Subject, From
etc...

2. The current Outlook client has access to multiple mailboxes. Is there a
way to know which
mailbox fired the event?

Dim m_Olapp As New Outlook.Application
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AddHandler m_Olapp.NewMail, AddressOf Me.eventhandlerNewMail
End Sub

Public Sub eventhandlerNewMail()
MsgBox("New Mail has arrived")

End Sub

Private Sub Form1_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
RemoveHandler m_Olapp.NewMail, AddressOf Me.eventhandlerNewMail
End Sub
 
K

Ken Tucker [MVP]

Hi,

Maybe this will help.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncodefun/html/code4fun03282003.asp

Ken
--------------------
I am creating an application that will sit on a client pc and monitor the
inbox. When an e-mail enters the inbox, then an even will be fired and I
will then be able to process the mail.

I have the following code that does fire the eventhandlerNewMail,
but I don't know how to do the following 2 things...

1. Get the NewMail object so I can look at the mailitems Subject, From
etc...

2. The current Outlook client has access to multiple mailboxes. Is there a
way to know which
mailbox fired the event?

Dim m_Olapp As New Outlook.Application
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AddHandler m_Olapp.NewMail, AddressOf Me.eventhandlerNewMail
End Sub

Public Sub eventhandlerNewMail()
MsgBox("New Mail has arrived")

End Sub

Private Sub Form1_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
RemoveHandler m_Olapp.NewMail, AddressOf Me.eventhandlerNewMail
End Sub
 
J

Jay B. Harlow [MVP - Outlook]

Roger,
For a list of articles on using Outlook from .NET see:

http://www.microeye.com/resources/res_outlookvsnet.htm

For a plethora of automating Outlook with VBA, VB6, and VBScript see:
http://www.outlookcode.com/

To avoid the Outlook security prompts its generally easiest to create a
properly constructed COM-Addin for Outlook 2003. There are other methods
available for other versions of Outlook...

See:
http://msdn.microsoft.com/library/d...dc_ol2003_ta/html/odc_olsecnotescomaddins.asp

Further info can be found at:
http://www.slipstick.com/dev/ol2003problems.htm
http://www.slipstick.com/outlook/esecup/admin.htm

The links I gave have samples of creating add-ins.

Both of these are good articles to start with:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnout2k2/html/odc_oladdinvbnet.asp

http://support.microsoft.com/?kbid=302896

Also, be certain you have explicitly installed the Outlook PIAs! The Outlook
2003 PIAs are an optional install, while the Outlook XP PIA is a download.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top