Monitor Outlook Shared Mailbox

rodsynergy

New Member
I am trying to monitor an Outlook shared mailbox. I have a code stage that works on my mailbox but fails on all shared mailboxes. There has been quite a few posts so far on this forum but I can't see any successful responses yet. Would appreciate it if you would reply if you have solved this puzzle!

My code stage is as follows:

Dim OutlookMailBox As String = [MailBoxName]
Dim outlook as Object
Dim ns As Object
Dim Inbox As Object
Dim i As Object

outlook = CreateObject("Outlook.Application")
ns = outlook.GetNamespace("MAPI")
Inbox = ns.Folders(OutlookMailBox)

[MailBoxExists] = False
For i = 1 To Inbox.Folders.Count
FolderNames = FolderNames + Inbox.Folders.Item(i).Name
If Inbox.Folders.Item(i).Name = InboxName Then
[MailBoxExists] = True
End If
Next i
[numberFolders] = i

Catch ex As System.Exception
ErrMessage = ex.Message
End Try

This passes back a true for the exists flag, and a list of all the sub folders in my mailbox when run for my account. For the shared mailbox it passed a false for the exists flag and the following error message: "The attempted operation failed. An object could not be found."
 

mkaefke

New Member
Hey rodsynergy,

as mentioned in Shared Mail Inbox Outlook you could either use redemtion or filter by recipient.
Here an working quick and dirty example.

Code:
Dim OutlookMailBox As String = "Shared Mailbox"
Dim outlook as Object
Dim ns As Object
Dim Inbox As Object
Dim i As Object

outlook = CreateObject("Outlook.Application")
ns = outlook.GetNamespace("MAPI")

DIM vRecipient = ns.CreateRecipient(OutlookMailBox)
DIM folder = ns.GetSharedDefaultFolder(vRecipient, 6)

For i = 1 To folder.Folders.Count
FolderNames = FolderNames + ";" + folder.Folders.Item(i).Name
Next i
[numberFolders] = i

Best regards
Marcel
 

rodsynergy

New Member
Much appreciated Marcel, I did manage to work it out and your example is very similar. My complete example below...
Try

Dim OutlookApp As object
Dim OutlookNamespace As Object
Dim Folder As MAPIFolder
Dim objOwner As Object
Dim olFolderInbox as object

Dim mailBoxName as string
Dim inboxName as string

'Remove quotes from email and folder
mailBoxName = replace(SharedMailBoxName,chr(34),"")
inboxName = replace([SharedInboxName],chr(34),"")

'Set default folder for inbox (6)
olFolderInbox = 6

'Conect to mailbox
OutlookApp = CreateObject("Outlook.Application")
OutlookNamespace = OutlookApp.GetNamespace("MAPI")
objOwner = OutlookNamespace.CreateRecipient(mailBoxName)
objOwner.Resolve

'Initialize sucess flag
[SharedMailBoxExists] = False

'If sucessfully resolved ownership of mailbox
If objOwner.Resolved Then
Folder = OutlookNamespace.GetSharedDefaultFolder(objOwner, olFolderInbox)

'If this is the inbox then we have a match
if Folder.name = inboxName Then
[SharedMailBoxExists] = True
End If

End If

Catch ex As System.Exception
[SharedErrMessage] = ex.Message
End Try
 

jonnymop5

Member
Hi rodsynergy,
I'm getting errors lots of compiler errors saying things are not declared. See below. What am I missing here?


Thanks!
Jon

View attachment 1579204552508.png


Much appreciated Marcel, I did manage to work it out and your example is very similar. My complete example below...
Try

Dim OutlookApp As object
Dim OutlookNamespace As Object
Dim Folder As MAPIFolder
Dim objOwner As Object
Dim olFolderInbox as object

Dim mailBoxName as string
Dim inboxName as string

'Remove quotes from email and folder
mailBoxName = replace(SharedMailBoxName,chr(34),"")
inboxName = replace([SharedInboxName],chr(34),"")

'Set default folder for inbox (6)
olFolderInbox = 6

'Conect to mailbox
OutlookApp = CreateObject("Outlook.Application")
OutlookNamespace = OutlookApp.GetNamespace("MAPI")
objOwner = OutlookNamespace.CreateRecipient(mailBoxName)
objOwner.Resolve

'Initialize sucess flag
[SharedMailBoxExists] = False

'If sucessfully resolved ownership of mailbox
If objOwner.Resolved Then
Folder = OutlookNamespace.GetSharedDefaultFolder(objOwner, olFolderInbox)

'If this is the inbox then we have a match
if Folder.name = inboxName Then
[SharedMailBoxExists] = True
End If

End If

Catch ex As System.Exception
[SharedErrMessage] = ex.Message
End Try
 
Top