Outlook modify and Save() MailItems - slow
I need to modify many MailItems in Outlook 2007.
I need the mails to immediately refresh in the main Outlook grid - the only way to do this I found is to call MailItem.Save().
foreach (var item in folder.Items)
{
var mail = item as MailItem;
if (mail != null) // process only MailItems
{
setUserProperty(mail, userPropKey, "speed test");
mail.Save(); // Save() to make the grid row redraw
if (++cnt == 10) // stop after 10 mails
break;
}
}
The problem is that Save() is slow on IMAP account - 1s per 1 Save() call, probably due to communication with server. On POP3 account it is ok.
The modification I need to make on every email is just changing a User property. I have a custom View defined in Outlook that shows a column with this property.
Is there a way to:
- make the user property local to PST, so that no communication with server is done on Save() ?
- do all the Save() calls in one batch ?
I'm setting user property on emails like this:
void setUserProperty(Outlook.MailItem item, string key, string value)
{
item.UserProperties.Add(key, Outlook.OlUserPropertyType.olText, true, Outlook.OlFormatText.olFormatTextText);开发者_开发技巧
item.UserProperties[key].Value = value;
}
精彩评论