Hot to speed up MailItems access

G

Guest

I get some properties from each MailItem in some folder:

_ItemsPtr spItems = spFolder->Items;
for (int j = 0; j < spItems->Count; j++)
{
_MailItemPtr spMailItem = spItems->Item( j+1 );
if ( !spMailItem )
continue;

// SenderEmailAddress, SenderName, SentOn, Subject and Recipients
properties reading here
}

But this code is very slow. Only 130 messages per second even without
reading any properties.

How can I speed up mail items processing greatly? I need to process
thousands of emails...

Thanks.
 
G

Guest

Thanks, Dmitry!
When I tried to use this method in OOM it always returns null. I don't know
why.
Using MAPI, IMAPITable.SetColumns works fine.
 
D

Dmitry Streblechenko

I am not sure what you mean - SetColumns in OOM does not return anything; it
simply tells Outlook which properties you are planning to access later from
the Items collection so that Outlook can make sure these properties get
cached from the underlying MAPI table.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
G

Guest

Sorry for the confusion. I mean that after calling SetColumns in OOM every
returned item from Items collection is null.
 
G

Guest

// spFolder - MAPIFolderPtr
_ItemsPtr spItems = spFolder->Items;
spItems->SetColumns( "SenderName" );
for (int j = 0; j < spItems->Count; j++)
{
_MailItemPtr spMailItem = spItems->Item( j+1 );
// spMailItem == null always, but without calling SetColumns everything
is ok.

if ( !spMailItem )
continue;
}
spItems->ResetColumns();
 
D

Dmitry Streblechenko

I had no problem running rthe script below (I used OutlookSpy - click
"Script Editor" button, paste the script, click Run)
What is your version of Outlook? What happens if you declare spMailItem as
IDispatch instead of _MailItemPtr?
Note that your code will fail if you encounter an item other than MailItem
(such as ReportItem).

set Folder = Application.ActiveExplorer.CurrentFolder
set Items = Folder.Items
Items.SetColumns("SenderName")
for each Item in Items
Debug.Print Item.SenderName
next

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

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