Using ItemAdd: Outlook COM Add-In for Oulook 2003 written in VB

M

m298908

I am trying to write an Outlook COM Add-In which checks the Inbox for new
items. I am using ItemAdd as opposed to NewMail since I will eventually
modify the code for different folders such as Sent Items.

I am having issues with the context of ItemAdd and possibly the layout of my
COM Add-In.

I have created a new .NET VB COM Add-in. In the connect.vb I have entered
the following code in the connection section:

Public Sub OnConnection(ByVal application As Object, ByVal connectMode As
Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
applicationObject = application
addInInstance = addInInst
Dim inEmailWatcher As New EmailWatcher
inEmailWatcher.Initialize_handler()
End Sub

Here is the code from my EmailWatcher.vb Public Class:

Imports Microsoft.Office.Core
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Outlook
Imports Extensibility
Imports System.Runtime.InteropServices
Imports MAPIPROPLib.MAPIPropWrapperClass
Imports Redemption.SafeMailItemClass

Public Class EmailWatcher
Dim oApp As Outlook.Application
Dim oInbox As Outlook.MAPIFolder
Dim oAllPublicFolders As Outlook.MAPIFolder
Dim oFRImportFolder As Outlook.MAPIFolder
Public WithEvents oInboxItems As Outlook.Items

Public Sub Initialize_handler()
MsgBox("Hello")
oApp = CreateObject("Outlook.Application")
oInbox =
oApp.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderInbox)
oInboxItems = oInbox.Items
oAllPublicFolders =
oApp.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olPublicFoldersAllPublicFolders)
oFRImportFolder = oAllPublicFolders.Folders("Export Folder")
MsgBox("oFRImportFolder set")
End Sub


Private Sub oInboxItems_ItemAdd(ByVal Item As Object, ByVal cancel As
Boolean)
MsgBox("oInboxItems ItemAdd initialized")
Dim sMessage As Redemption.SafeMailItem
Dim oMailItem As MailItem
Dim oFRImportMessage As MailItem
Dim oMessage As Object
Dim wrapper As New MAPIPROPLib.MAPIPropWrapperClass
sMessage = CreateObject("Redemption.SafeMailItem")
sMessage.Item = Item
If sMessage.SenderEmailAddress = "(e-mail address removed)" Then
MsgBox("From Name: " & sMessage.SenderName)
MsgBox("From Email: " & sMessage.SenderEmailAddress)
MsgBox("Subject: " & wrapper.GetOneProp(oMessage, &H37001E))
MsgBox("Date: " & wrapper.GetOneProp(oMessage, &HE060040))
MsgBox("MessageID: " & wrapper.GetOneProp(oMessage, &H1035001E))
'oFRImportMessage = oMessage.Copy
'MsgBox("message copied")
'oFRImportMessage.Move(oFRImportFolder)
'MsgBox("message moved")
End If
End Sub

End Class

This code is not complete yet. The COM Add-In loads and using msgboxes, i
can see that it completes the Initialize_handler() section completely.

I cannot get the oInboxItems_ItemAdd to run at all. Does it need to be
specifically called from the Initialize_handler() section? All the code
examples (thought it was VBA) did not show a specific call. My assumption was
the Public WithEvents oInboxItems As Outlook.Items was stated, the ItemAdd
would work. I am new to this, so specific help is appreciated.

Thanks

Jeff
 

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