How to download >1 MB Email attachment using EWS in C#

1.1k views Asked by At

I need to Download Email Attachments from Exchange Server using Exchange Web Service API 2.1 I was tried FindItemResults. Minimum size of files can be download. but, If the file size is above 1 MB(I tried with 2MB file). It takes More time and throw Time expired Exception. I know Why this exception. But My question is, can I download big size of attachments?

2

There are 2 answers

2
Tholle On BEST ANSWER

You should use GetItem, not FindItem. Use FindItem to get the Id och the mail with the attachment, then get the entire mail with GetItem.

Note that the FindItem operation only returns the first 512 bytes (255 Unicode characters) of any property; therefore, message header collections that are longer than 512 bytes will be truncated.

You can modify the code in this great answer to suit your needs: Exchange Web Services API : get mail attachments

3
Glen Scales On

The default timeout in the EWS Managed API is 90 seconds so if the download isn't completing in that time you'll get a time out exception thrown. You can just increase the timeout by setting the timeout property on the ExchangeService class eg

Service.Time = 300000;

300000 = 300000 milliseconds or 5 minutes

Cheers Glen