Skip to content

Unable to download FileAttachment #55

@bstoinev

Description

@bstoinev

Hello!
I'm having a hard time downloading attachments.

The below code never downloads an attachment:

        private Dictionary<string, Stream> DownloadAttachments(EmailMessage message)
        {
            var result = new Dictionary<string, Stream>();

            var pdfAttachments = message.Attachments.Where(a => a.ContentType.Equals("application/pdf", StringComparison.OrdinalIgnoreCase));

            Log.Debug($"{pdfAttachments.Count()} attachment(s) found.");

            foreach (FileAttachment attachment in pdfAttachments)
            {
                var ms = new MemoryStream(attachment.Size);
                attachment.Load(ms);
                result.Add(attachment.Name, ms);
            }

            return result;
        }

No error is thrown; the attachment.Content property is null, and the length of the MemoryStream is 0. The metadata for the attachment is downloaded correctly though. I can obtain attachment filename, size, and content type.
Please note, that the EmailMessage message argument is already bound to an ExchangeService by the calling method using the ItemSchema.Attachments amongst other schemas.

Any help/insights would be greatly appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions