locked
Is there a way to tell the difference between an attached file, and an image that is embedded in an email? RRS feed

  • Question

  • When Outlook receives an email, it appears that attached files and embedded images are carried as Attachments.  In looking at emails and the individual attachments/embedded images with Outlook Spy, I do not see anything that would tell me which is which.  Obviously Outlook knows the difference ... is there something that I'm missing?
    mdpowers
    Monday, July 18, 2011 11:22 PM

Answers

  • Hi,

     

    We can identify this by using PropertyAccessor.

     foreach (Attachment attachment in mailitem.Attachments)
     {
         //if embedded image return the content - id  
         //otherwise return empty
         string value = attachment.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E");
         
         if(null != value)
        {
              // do something
         }    
         
     }



    venugopal


    • Marked as answer by mdpowers-slo Tuesday, July 19, 2011 3:19 PM
    Tuesday, July 19, 2011 4:52 AM

All replies

  • Hi,

     

    We can identify this by using PropertyAccessor.

     foreach (Attachment attachment in mailitem.Attachments)
     {
         //if embedded image return the content - id  
         //otherwise return empty
         string value = attachment.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E");
         
         if(null != value)
        {
              // do something
         }    
         
     }



    venugopal


    • Marked as answer by mdpowers-slo Tuesday, July 19, 2011 3:19 PM
    Tuesday, July 19, 2011 4:52 AM
  • Hi venugopal,

    Thank you very much!  That works!

    mdpowers


    mdpowers
    Tuesday, July 19, 2011 3:20 PM
  • There are some ways that attachments are embedded that may or may not produce a ContentID property on the attachment. For a complete check as to whether or not an attachment is embedded you can also check for ContentLocation ("http://schemas.microsoft.com/mapi/proptag/0x3713001E") not being null, and for AttachFlags ("http://schemas.microsoft.com/mapi/proptag/0x37140003") not being 4 (that's a Long property).
     
    Also, if attachment.Type == olEmbeddedItem or it == olOLE or it == olByReference the attachment is embedded.
     
    I usually do a check first on the Outlook object model property Attachment.Type, then if those don't show an embedded item I check the PropertyAccessor tags mentioned above.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "mdpowers-slo" <=?utf-8?B?bWRwb3dlcnMtc2xv?=> wrote in message news:97201ddd-4086-46ca-8b79-0f7442f6bf3b...

    Hi venugopal,

    Thank you very much!  That works!

    mdpowers


    mdpowers

    Ken Slovak MVP - Outlook
    Tuesday, July 19, 2011 3:27 PM
  • Thanks Ken,

    I'll check that out.  I had already tried the attachment.Type ... on my debug machine, Win7x64, Outlook 2010 x86, the embedded images had the same type as the attached files, olByReference, not olEmbeddedItem.

     


    mdpowers
    Tuesday, July 19, 2011 3:56 PM
  • Is there any way to determine if an embedded image is part of a signature?
    mdpowers
    Tuesday, July 19, 2011 4:01 PM
  • You need to save the item to get an accurate representation of how the attachment was attached. Attached by reference changes in many cases when the item is saved to the final status.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "mdpowers-slo" <=?utf-8?B?bWRwb3dlcnMtc2xv?=> wrote in message news:60957b2d-7f97-4624-8a8e-cd7f3fe10124...

    Thanks Ken,

    I'll check that out.  I had already tried the attachment.Type .... on my debug machine, Win7x64, Outlook 2010 x86, the embedded images had the same type as the attached files, olByReference, not olEmbeddedItem.

     


    mdpowers

    Ken Slovak MVP - Outlook
    Tuesday, July 19, 2011 5:41 PM
  • The answer to that depends on how the signature was attached and what version of Outlook and for earlier versions if WordMail is being used.
     
    In some cases, if you parse the HTMLBody property you'll see text something like this:
     
    <a name="_MailAutoSig">
     
    That's the start of a signature. If an image is part of that signature tag it will be referenced there with something like this type of HTML:
     
    src="cid:image001.jpg@01CC4619.22A90250">
     
    It's hard to figure out what's what though. The easiest way is to create a brand new blank email item and check that for what's in HTMLBody before any text is added. That of course though doesn't guarantee that a non-standard signature is being used in an item instead of the standard signature.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "mdpowers-slo" <=?utf-8?B?bWRwb3dlcnMtc2xv?=> wrote in message news:c81ae941-6fd3-4850-83af-615c587d9278...
    Is there any way to determine if an embedded image is part of a signature?
    mdpowers

    Ken Slovak MVP - Outlook
    Tuesday, July 19, 2011 5:41 PM
  • I'm getting this on both incoming emails and items that have already been sent.
    mdpowers
    Tuesday, July 19, 2011 6:53 PM
  • Hi Ken,

    In my code i have something like that:

    public static bool IsEmbeddedAttachment(Outlook.Attachment attachment)
            {
                //Anexos que não são embedded são obrigatóriamente olByValue, porém os embedded podem ser de qualquer tipo
                if (attachment.Type != Outlook.OlAttachmentType.olByValue)
                    return true;
    
                //Busca a propriedade contentID do anexo. Anexos embedded não precisam necessáriamente gerar um ContentID. Anexos fixos não geram ContentID
                string strATTACH_CONTENT_ID = attachment.PropertyAccessor.GetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x3712001E").ToString();
    
                //Busca a propriedade contentLocation. Para que o anexo seja embedded é necessario que essa propriedade esteja vazia ou nulla
                string strATTACH_CONTENT_LOCATION = attachment.PropertyAccessor.GetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x3713001E").ToString();
    
                if (!string.IsNullOrWhiteSpace(strATTACH_CONTENT_ID) || !string.IsNullOrWhiteSpace(strATTACH_CONTENT_LOCATION))
                {
                    //Busca a propriedade AttachFlag se for diferente de 4 é uma imagem embedded
                    if ((int)attachment.PropertyAccessor.GetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x37140003") == 4)
                        return true;
                }
    
                                                     
                if ((int)attachment.PropertyAccessor.GetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x37050003") == 6)
                {
                    return true;
                }
                                                     
                if ((int)attachment.PropertyAccessor.GetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x37140003") == 4)
                {
                    return true;
                }
    
                return false;
            }

    And was working very well until last week. 

    I have a problem with a single email. This email attachments possess 2 PDF type files. These files are not embbed in the email, but they have the contentId property. Could you tell me why? or if its possible discovery why this happens?

    PS.: Sorry about my english.

    Att's,

    Anderson Rissardi.

    Monday, April 6, 2015 2:45 PM
  • You cannot rely on PR_ATTACH_CONTENT_ID or PR_ATTACH_FLAGS to be indication of an embedded image. It is perfectly legal for any attachment to have PR_ATTACH_CONTENT_ID - Lotus Notes adds that property to all attachments.

    The only reliable way is to look at the HTML body to figure out which attachments are actually used by the <img> tags.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, April 6, 2015 2:52 PM