This project is read-only.

EWS Managed API - Attachment

Sep 23, 2014 at 7:52 PM
I bind to an existing email that has an attachment (a sample text file - txt). However, the ContentType and ContentLocation are blank. I tried to set it and it complaint that attachment cannot update.

How do you set the ContentType/ContentLocation for an existing attachment to an existing email?
        // As a best practice, limit the properties returned by the Bind method to only those that are required.
        PropertySet propSet = new PropertySet(BasePropertySet.IdOnly);
        propSet.Add(EmailMessageSchema.Id);
        propSet.Add(EmailMessageSchema.Subject);
        propSet.Add(EmailMessageSchema.DisplayTo);
        propSet.Add(EmailMessageSchema.ParentFolderId);
        propSet.Add(EmailMessageSchema.Attachments);
        propSet.Add(EmailMessageSchema.MimeContent);
        propSet.Add(EmailMessageSchema.Body);

        propSet.Add(ItemSchema.Attachments);
        propSet.Add(ItemSchema.MimeContent);
        propSet.Add(ItemSchema.Body);

        string selectedEmailID = "AQIARgAAAxhegHoKyHdPnpK1r9EyWbYHAGdo6ZtZ4hlEv48Att1+o/wAAAIEAwAAAGdo6ZtZ4hlEv48Att1+o/wAAAACl63jAAAALgAAAxhegHoKyHdPnpK1r9EyWbYBAGdo6ZtZ4hlEv48Att1+o/wAAAIEAwAAAA==";

        EmailMessage message = EmailMessage.Bind(service, selectedEmailID, propSet);

        if (message.HasAttachments)
        {

           for (int i = 0; i < message.Attachments.Count; i++)
           {

              if (message.Attachments[i] is FileAttachment)
              {

                 FileAttachment fa = message.Attachments[0] as FileAttachment;
                 fa.Load();
             fa.ContentType = "text/plain";
              }

           }
Thank you