We want to retrieve emails from our Office365 Inbox from a C# Application. We used to use EWS but want to change to Graph. However, if we retrieve an email via Graph it takes twice the time as with EWS (~400ms vs ~200ms).
Here is the EWS code:
ExchangeService service = <...>;
PropertySet properties = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.From,
EmailMessageSchema.DateTimeSent, EmailMessageSchema.Subject,
EmailMessageSchema.CcRecipients, EmailMessageSchema.BccRecipients,
EmailMessageSchema.Importance, EmailMessageSchema.ToRecipients,
EmailMessageSchema.Attachments, EmailMessageSchema.Size,
EmailMessageSchema.Sender, EmailMessageSchema.Body,
EmailSchema.MailComment, EmailSchema.MailImportance,
EmailSchema.MailMessageClass, EmailMessageSchema.DateTimeReceived,
EmailSchema.MailTransportHeader);
properties.RequestedBodyType = Microsoft.Exchange.WebServices.Data.BodyType.HTML;
EmailMessage mail = EmailMessage.Bind(service, "<mailid>", properties);
Here is the Graph code:
GraphServiceClient client = <...>;
Message msg = client
.Users["<user>"]
.Messages["<mailid>"]
.Request()
.Select("id,parentFolderId,isRead,from,sentDateTime,subject,ccRecipients,bccRecipients,attachments,importance,toRecipients,sender,body,receivedDateTime")
.Expand("microsoft.graph.message/attachments," +
"singleValueExtendedProperties($filter=Id eq 'Long 0xe08'" +
" or Id eq 'String 0x1a'" +
" or Id eq 'String 0x7d'" +
" or Id eq 'Integer 0x17'" +
" or Id eq 'String 0x3004')")
.GetAsync()
.Result;
Why is Graph slower? What should we change to make Graph as performant as EWS?