Attachments and EWS in Exchange

Exchange

Learn about attachments and how your EWS Managed API or EWS in Exchange client represents them.

Last modified: May 22, 2014

Applies to: EWS Managed API | Exchange Online | Exchange Server 2013 | Office 365

In this article
Types of attachments
How are attachments represented programmatically?
Inline attachments
In this section
Additional resources

Usually, attachments are associated with email items, but in fact, all EWS items — email messages, calendar items, contacts, tasks — can include attachments.

EWS categorizes attachments into two groups: file attachments and item attachments.

  • Item attachments: Strongly-typed EWS items, such as email messages and calendar items, that are attached to another strongly-typed EWS item. Any strongly-typed item that can be created by using the EWS Managed API or EWS can be used as an item attachment. The content of an item attachment is the strongly-typed item, which provides easy access to all its properties. Item attachments can have their own item attachments, so a hierarchy of item attachments (or nesting of attachments) is possible.

  • File attachments: Any file, such as a .txt, .jpg, .zip, .pdf, or even a .msg file. A file attachment only has a few properties, one of which is the base-64 encoded content of the file.

When you add or retrieve attachments from an item, you'll do it differently depending on whether it's a file attachment or an item attachment. For example, to add a file attachment to an item, you can just pass in the location of the file. To add an existing item as an item attachment, you actually have to copy the properties or the MIME content of the existing item to a new item attachment; you can't just bind to the existing item. So distinguishing between the two types of attachments is important. More details about the differences between item attachments and file attachments are discussed in the articles In this section.

Attachments are stored in a collection on the EWS item. The attachments collection is made up of file attachments and/or item attachments. Metadata about the attachment collection is available when you get an item by using the EWS Managed API Item.Bind method or the EWS GetItem operation, but additional calls are required to actually retrieve the contents of the attachments.

Table 1.  Item metadata about attachments

Metadata entity

EWS Managed API property

EWS element

Attachment indicator (does not flag inline attachments)

Item.HasAttachments

HasAttachments

Attachment collection

Item.Attachments

Attachments

Attachment ID

Attachment.Id

AttachmentId

Table 2.  Attachment entities

Attachment type

EWS Managed API class

EWS element

File attachment

FileAttachment

FileAttachment

Item attachment

ItemAttachment

ItemAttachment<TItem>

ItemAttachment

Inline attachments are a special breed of attachment. Both file attachments and item attachments can be inline attachments. An inline attachment appears as part of the body content and retains its position relative to the rest of the content in the item.

An attachment is an inline attachment if the EWS Managed API IsInline property or the EWS IsInline element is set to true. Inline attachments use the following optional properties and elements to identify the location of an inline attachment:

Note that the EWS Managed API HasAttachments property and the EWS HasAttachments element do not reflect the existence of inline attachments, and that's why inline attachments are also called hidden attachments. So if you set the EWS Managed API IsInline property or the EWS IsInline element to true, and the item has no other attachments, HasAttachments will be set to false. If your client uses HasAttachments to populate an attachment indicator or icon on an email, be aware that the icon will not appear for emails with inline attachments.

Show:
© 2015 Microsoft