EWS显示电子邮件非常慢

时间:2019-05-24 09:31:10

标签: c# asp.net .net exchange-server exchangewebservices

我在我的应用程序代码中使用Exchange Services在应用程序UI上显示电子邮件列表。但是,它能够检索电子邮件列表。但是显示所有设置需要非常长的时间。如果我减少显示的电子邮件数量,则显示时间会减少。

public static List<EmailMsg> GetEmailListInFolder(string folderName)
    {
        var folderId = GetFolderId(folderName);
        var service = GetExchangeService();

        if (folderId != null)
        {
            var emails = new List<EmailMsg>();
            var count = 0;
            var findResults = service.FindItems(folderId, new ItemView(100));

            foreach (var item in findResults.Items)
            {
                var emailPropertySet = new PropertySet(
                    BasePropertySet.FirstClassProperties,
                    new PropertyDefinitionBase[]{
                            new ExtendedPropertyDefinition(4115, MapiPropertyType.Binary)
                    });

                var message = EmailMessage.Bind(service, item.Id, emailPropertySet);

                emails.Add(new EmailMsg(folderName, count++, item.Id.UniqueId, message.Subject, message.DateTimeReceived.ToString("yyyy-MMM-dd HH:mm:ss"), ""));
            }
            return emails;
        }

        return null;
    }

当我调试代码并发现在进行下一行之前,该行需要花费几秒钟的时间。

var message = EmailMessage.Bind(service, item.Id, emailPropertySet);

请给我建议一种减少电子邮件项目加载时间的方法。谢谢

1 个答案:

答案 0 :(得分:0)

您将退回所有BasePropertySet.FirstClassProperties
您可能需要考虑更改此设置,以仅返回所需的属性。

来自msdn的FirstClassProperty列表:

Id
ParentFolderId
ItemClass
Subject
Sensitivity
Body
Attachments
DateTimeReceived
Size
Categories
Importance
InReplyTo
IsSubmitted
IsDraft
IsFromMe
IsResend
IsUnmodified
InternetMessageHeaders
DateTimeSent
DateTimeCreated
AllowedResponseActions
ReminderDueBy
IsReminderSet
ReminderMinutesBeforeStart
DisplayCc
DisplayTo
HasAttachments
Culture
EffectiveRights
LastModifiedName
LastModifiedTime
IsAssociated
WebClientReadFormQueryString
WebClientEditFormQueryString
ConversationId
Flag
InstanceKey
EntityExtractionResult
Sender
ToRecipients
CcRecipients
BccRecipients
IsReadReceiptRequested
IsDeliveryReceiptRequested
ConversationIndex
ConversationTopic
From
InternetMessageId
IsRead
IsResponseRequested
ReplyTo
References
ReceivedBy
ReceivedRepresenting

您正在加载附件。要避免这么大的负担,您可以: