开发者

Outlook Object Model - Detecting Mailboxes

开发者 https://www.devze.com 2023-02-20 19:25 出处:网络
I have a Delphi 2006 BDS application with the following code to iterate outlook mailboxes and then the Inbox and Sent Items within the mailbox:

I have a Delphi 2006 BDS application with the following code to iterate outlook mailboxes and then the Inbox and Sent Items within the mailbox:

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

    for i := 1 to mailbox.Count do
      if Pos('MAILBOX', Uppe开发者_JAVA百科rCase(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 under Outlook 2007 but doesn't in 2010 because the mailboxes do not contain the word 'Mailbox'. Therefore I am after an alternative method of extracting JUST the mailboxes (not public folders etc) from within Outlook and their subsequence Inbox and sent items folders. Any ideas?


In Outlook folders can be typed and have a DefaultItemType property. Replacing

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

with

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

should give you the folders that by default store only mail messages.

Mail messages can of course be stored in untyped folders as well, but as olMailItem has

olMailItem = $00000000;

as its value, it is the default for all untyped folders as well. So basically any untyped folder by default stores mail items.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号