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!
Hello!
I'm having a hard time downloading attachments.
The below code never downloads an attachment:
No error is thrown; the
attachment.Contentproperty is null, and the length of theMemoryStreamis 0. The metadata for the attachment is downloaded correctly though. I can obtain attachment filename, size, and content type.Please note, that the
EmailMessage messageargument is already bound to anExchangeServiceby the calling method using theItemSchema.Attachmentsamongst other schemas.Any help/insights would be greatly appreciated!