Outlook Object Model - Mailbox Discovery

I have a BDS Delphi 2006 application with the following code to iterate Outlook mailboxes and then inbound and outbound items in a mailbox:

  try
    nameSpace := outlook.GetNameSpace('MAPI');
    // load the mailboxes
    mailbox := NameSpace.Folders;

    for i := 1 to mailbox.Count do
      if Pos('MAILBOX', UpperCase(mailbox.Item[i].Name)) > 0 then
      begin
        rootNode := trvwOutlookFolders.Items.AddChildObject(nil, mailbox.Item[i].Name, nil);

        for j := 1 to mailbox.Item[i].Folders.Count do
          if (Pos('INBOX', UpperCase(mailbox.Item[i].Folders[j].Name)) > 0) or
             (Pos('SENT ITEMS', UpperCase(mailbox.Item[i].Folders[j].Name)) > 0) then
          begin
        // do processing
          end;

      end;

  finally
    outlook := Unassigned;
  end;
end;

The code works fine in Outlook 2007, but not in 2010, because the mailboxes do not contain the word "Mailbox". Therefore, I get an alternative method for extracting JUST mailboxes (not public folders, etc.) from Outlook and their subsequence "Inbox" and folders of sent items. Any ideas?

0
source share
1 answer

In Outlook folders, you can enter and set the DefaultItemType property. Replacement

if Pos('MAILBOX', UpperCase(mailbox.Item[i].Name)) > 0 then

with

if (mailbox.Item[i].DefaultItemType = olMailItem) then

, .

, , , olMailItem

olMailItem = $00000000;

, . , .

+7

All Articles