Get attachment type of an email

Add-in Express™ Support Service
That's what is more important than anything else

Get attachment type of an email
 
Subscribe
Schröder Heiko




Posts: 2
Joined: 2025-02-05
Hello,

I want to iterate the mails and each attachment of them.
I need only the attachments, which are not embedded. That means, I don't want images from inside the mail.

I've found some source codes for VBA, which can't converted to Delphi.

For Each olMailItem In olFolder.Items
        If TypeName(olMailItem) = "MailItem" Then
            For i = 1 To olMailItem.Attachments.Count
                Set olAttachment = olMailItem.Attachments(i)
                If olAttachment.Type = olByValue Then
                    Debug.Print "Attachment: " & olAttachment.FileName & " (normal)"
                ElseIf olAttachment.Type = olEmbeddeditem Then
                    Debug.Print "Attachment: " & olAttachment.FileName & " (embedded)"
                End If
            Next i
        End If
    Next olMailItem


This is my code in Delphi.

for var e : integer := iMailStart to mailItems.Count do
  begin

    IDisp := mailItems.Item(e); 
    if IDisp.QueryInterface(IID__MailItem, mail) = S_OK then  
    begin
       for var a : integer := 1 to mail.Attachments.Count do
       begin
            strAttachmentName := mail.Attachments.Item(a).FileName;  /// works

            // no embedded elements 
            if (mail.Attachments.Item(a).type_ = olEmbeddeditem) then /// <<<------
               continue

            else
            // alternate sourcecode
            
      end;
    end;


My problem is, that I don't get the right type information... What's wrong?

For your information: I did typecast the Outlook2000 to Outlook2010. I don't need older versions of Outlook.
Posted 05 Feb, 2025 14:00:02 Top
Andrei Smolin


Add-in Express team


Posts: 19075
Joined: 2006-05-11
Hello Heiko,

My understanding is: this topic doesn't have a precise solution. I would suggest that you check the code of the example I wrote a while back: https://www.add-in-express.com/files/projects_pub/adx-ol-get-embedded-attachment-vb.zip. It is based on suggestions by Ken Slovak - a recognized guru of programming for Outlook. If the approach the code demonstrates doesn't work for you, I suggest googling for what Ken Slovak said about embedded attachments.

You can start with this page: https://learn.microsoft.com/en-us/archive/msdn-technet-forums/08c45486-cd48-4836-be90-d61883e92824

See also these searches:

https://learn.microsoft.com/en-us/search/?terms=%22ken%20slovak%22%20%22embedded%20attachments%22
https://learn.microsoft.com/en-us/search/?terms=%22ken%20slovak%22%20%22embedded%20attachments%22&dataSource=previousVersions

Regards from Poland (GMT+2),

Andrei Smolin
Add-in Express Team Leader
Posted 05 Feb, 2025 14:52:32 Top
Schröder Heiko




Posts: 2
Joined: 2025-02-05
Hello,

many thanks for your fast repsonse. I will try it.
Posted 05 Feb, 2025 16:01:40 Top