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', 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 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
with
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
as its value, it is the default for all untyped folders as well. So basically any untyped folder by default stores mail items.