Warm tip: This article is reproduced from serverfault.com, please click

Get Email Message using Exchange webservices without attachment, using C# (in UiPath)

发布于 2021-02-02 17:03:20

I am getting emails from a mailbox using exchange webservices using a custom code block in C# (I'm not versed in C# at all so forgive code quality!) in UiPath. I am passing the exchange service and folder ID as arguments to the code block. I noticed that when there was a large attachment on the email it took significantly longer. I am not interested in the attachment I just want to be able to access some information about the email. This was my initial code:

//Search for oldest email 
ItemView objView = new ItemView(1);
objView.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
FindItemsResults<Item> lstItems = objServer.FindItems(in_FolderID, objView);

//Bind to email from result
if(lstItems.Count() == 0) 
{
    Console.WriteLine("Inbox appears to be empty");
    out_ExchangeMessage = null;
    out_InternetMessageID = null;
}
else
    {
        Item objItem = lstItems.ElementAt(0);
        Console.WriteLine("Retrieving email: " + objItem.Subject);
        PropertySet objPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent, EmailMessageSchema.IsRead,ItemSchema.Attachments,ItemSchema.TextBody);
        out_ExchangeMessage = EmailMessage.Bind(objServer,objItem.Id, objPropertySet);
        out_InternetMessageID = out_ExchangeMessage.InternetMessageId;
        Console.WriteLine("Message Retrieved: " + out_ExchangeMessage.InternetMessageId);
    }

I tried removing ItemSchema.Attachments so this line reads as follows. But the email still takes significantly longer to download

PropertySet objPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent, EmailMessageSchema.IsRead,ItemSchema.TextBody);

Is there a way to speed up the retrieving of emails with large attachments?

Questioner
UZEE100
Viewed
0
Glen Scales 2021-02-03 06:44:41

Because your including ItemSchema.MimeContent in your propertyset that is going to give you the whole MimeStream of the Message including attachments. If you don't require the MimeStream don't request it. Eg you should be able to get all the other properties of the Message eg body,subject,headers etc from other properties so it would only be required if you wanted to save the message.