Exchange Server TechCenter > Exchange Server Forums > Development > EWS Managed API and inline images
Ask a questionAsk a question
 

QuestionEWS Managed API and inline images

  • Tuesday, November 03, 2009 2:15 PMRPDev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Is it possible for us to retrieve inline images via the EWS Managed API?  If not what is the best to handle this the emails with inline all look like they have broken link images when they are rendered in our client.

    I would even be open to attaching them to the email message as an actual attachment just so the user would be able to them.  If it is not possible retrieve these images is there a plan to add this feature to the EWS Managed API?


All Replies

  • Tuesday, November 03, 2009 6:58 PMDieBagger Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Is it possible for us to retrieve inline images via the EWS Managed API?  If not what is the best to handle this the emails with inline all look like they have broken link images when they are rendered in our client.

    I would even be open to attaching them to the email message as an actual attachment just so the user would be able to them.  If it is not possible retrieve these images is there a plan to add this feature to the EWS Managed API ?
    Hi RPDev,

    yes you can use inline images with EWS Managed API. To insert an inline image, use:


    FileAttachment attachment =msg.Attachments.AddFileAttachment(a.Filename, a.Data);
    attachment.IsInline = true;
    attachment.ContentType = "GIF/Image";
    


    if you retrieve a mail with inline images, just check for the "IsInline" property in the attachments.

    Was this what you're looking for?
  • Tuesday, November 03, 2009 8:53 PMRPDev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks for your reply,

    I need to know how to retrieve an inline that is already in a message?  To me it looks as if EWS is not exposing inline images.  In the body I get something like <img src="cid:76351935-49c3-4018-9a6e-a178fe0e1f8c">.  If I am correct in saying EWS is not exposing them right now are there plans to add this feature in the future.

    Any advice on this would be helpful.

    Btw we are on Exchange 2007 sp1,
  • Thursday, November 05, 2009 1:28 PMDieBagger Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Well for me it (kinda) works.

    If I open a mail with inline attachments they show up in the attachment list, so in your case:

    foreach (Attachment a in msg.Attachments)
    {
      if(a.Name.Equals("76351935-49c3-4018-9a6e-a178fe0e1f8c"))
      { 
         a.Load();
         MemoryStream ms = <span class=code-keyword>new</span>MemoryStream(((FileAttachment)a).Content);
         Image returnImage = Image.FromStream(ms);
      }
    }
    
    should give you the image file.

    The only problem for me is that not all image attachments have the "IsInline" property set correctly...
  • Thursday, November 05, 2009 9:28 PMRPDev Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thaks for your response,

    I never get the CID as for the name, I get a name of "Picture (Device Independent Bitmap)".

    The inline image is really an ItemAttachment when I look into the object most attributes are null such as content type and such Although I can see an Exchange ID for that item.
  • Friday, November 06, 2009 12:01 PMDieBagger Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I did some further testing with this and it seems I was a bit wrong, here is where I currently stand:
    • the Attachment.ContentId property is the property that matches with the id given in the body (<img src="cid:bla">)
    • the Attachment.ContentId property is always null if the image isn't inline
    • the Attachment.IsInline is set correctly when the mail was sent from another exchange account (it was not correctly set with mails I copied from an imap account)
    Oh and for me the image isn't an ItemAttachment, it's an an "Microsoft.Exchange.WebServices.Data.FileAttachment" object.