none
Extracting only "real" attachments from outlook mail item RRS feed

  • Question

  • I’m trying to get all "real" attachments from a mail object.

    When i try to get only items with

     'http://schemas.microsoft.com/mapi/proptag/0x3712001E'=null 

    then i missed real attachments in some mails.

    When i try to get only items with    'http://schemas.microsoft.com/mapi/proptag/0x3712001E'=null

    or 

    'http://schemas.microsoft.com/mapi/proptag/0x3713001F' = null 

    then I'm getting embedded items (like Images). Items that are not listed in

    the attachments list of outlook.

    Please help

    Here is the source code in Delphi

    Function IsRealAttachment (IAttachment:IDispatch):Boolean;

    var

      Attachment1 :Outlook_tlb.Attachment;

      const

        PR_ATTACH_CONTENT_ID  = http://schemas.microsoft.com/mapi/proptag/0x3712001E';

        PR_ATTACH_CONTENT_LOCATION =  'http://schemas.microsoft.com/mapi/proptag/0x3713001F';

    begin

      Attachment1 := IAttachment as Outlook_tlb.Attachment;

      Result := ((Attachment1.PropertyAccessor.GetProperty(PR_ATTACH_CONTENT_ID) = '') OR

                 (Attachment1.PropertyAccessor.GetProperty(PR_ATTACH_CONTENT_LOCATION) = ''));

                             

    end;


    Thursday, December 28, 2017 12:09 PM

All replies

  • Is there a reason that you are not using the Attachments collection of a MailItem object to enumerate the individual Attachment objects?

    • Edited by RLWA32 Thursday, December 28, 2017 12:54 PM
    Thursday, December 28, 2017 12:53 PM
  • Hi ilantep,

    This forum(Outlook for Developer) is for development issue related to Outlook Object Model. 

    As RLW32 said, We could try to get Attachments collection of a MailItem object which are all listed in the attachments list of outlook. You could get a mail item object and then get the attachments collection and then loop in it to get each attachment.

    You could try to refer to below link for a simply code in C# and try to adjust it in delphi.

    How to: Programmatically Save Attachments from Outlook E-Mail Items

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 29, 2017 5:30 AM
  • I believe i'm doing it:

      // Get email data
      // =======================================================
      IFolder := IMail.Parent as MAPIFolder;
      Folder_EntryID := IFolder.EntryID;
      Folder_StoreID := IFolder.StoreID; // needed for GetItemFromID

      // send the data of email to Yanshuf (The unipaas application)
      ShareMemU.SetShareData(MailProps);

      // Attachements
      RealAttachments.AttachmentsFileNames.Clear;

    //  StATT := '';
      if (IMail.Attachments.Count > 0) then
      begin
        for attInd := 1 to IMail.Attachments.Count do
        begin
    //                    showmessage ('bbbbbbb');
          AttachmentIsAEmbeded := false;
          AttachmentIsNotRealAttachment := false;

          // Scan attachments items
          if (IMail.Attachments.Item(attInd).type_ = olByValue) then // The attachment is a copy of the original file and can be accessed even if the original file is removed.
          begin

    Sunday, December 31, 2017 10:54 AM
  • Define exactly what you mean by "real attachment".
    Sunday, December 31, 2017 11:29 AM
  • Hello ilantep,

    I'm wondering what's the "real attachment" now.  How much total attachments in your mail? How much real attachments in your mail? What's value of IMail.Attachments.Count?

    Could you please show some screenshots to tell us what do you mean "real" attachments and what is "not-real"? You could share the screenshots via One Drive and then put link address here.

    Best Regards,

    Terry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 2, 2018 9:56 AM