Outlook change and save () MailItems - slowly

I need to change many MailItems in Outlook 2007.

I need the mail to be updated immediately in the main Outlook grid - the only way I can do this 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 slower in the IMAP account - 1 s for 1 call to Save (), possibly due to communication with the server. On a POP3 account, this is normal.

The modification that I have to make for each email just changes the user's property. I have a custom view defined in Outlook that shows a column with this property.

Is there any way:

  •  
  • make the user property local to PST so that communication with the server is not performed in Save ()?  
  • make all Save () calls in one batch?

:

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;
}
+3

Source: https://habr.com/ru/post/1719531/


All Articles