Outlook Mail attachments not completely shown

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

Outlook Mail attachments not completely shown
 
Thomas Bach


Guest


Hi,

i try to read attachments form an Outlook Mail object and add the entries to a list.

By complex mails with many attachments (e.g. 18), the Count property is some times different. If i press the button calling this function immediatly, the Count is not 18. If i wait a little bit, the Count ist correct set to 18.

It seems, that the attachments need time to load. Is there any way to check, if the loading is complete or is there any other reason




 For i As Integer = 1 To mailAttachments.Count
                        Dim currentAttachment As Outlook.Attachment = mailAttachments.Item(i)
                        If Not IsNothing(currentAttachment) Then

                            Dim Mailattachment As OIMailAttachment = New OIMailAttachment()
                            With Mailattachment
 X FileName = currentAttachment.FileName
 X DisplayName = currentAttachment.DisplayName
 X Type = currentAttachment.Type
                            End With

                            liMailAttachments.Add(Mailattachment)


                        End If
                    Next


Also another question: If i try to read the attachments from an html Mail-Format, i get also the embedded imgages in the list. Is there any way to extract only the 'real' attachments?

Regards

Thomas
Posted 26 Mar, 2012 13:27:37 Top
Eugene Astafiev


Guest


Hi Thomas,

Thank you for providing us with a snippet of code.

I have noticed that you don't release underlying COM objects correctly. For example, the currentAttachment object is not released each time the for loop iterates. Please read more about this in the http://www.add-in-express.com/creating-addins-blog/2008/10/30/releasing-office-objects-net/ article on our technical blog.

Please check out the Type property of the Attachment class if want to recognize an embedded image.
Posted 26 Mar, 2012 14:32:00 Top
Thomas Bach


Guest


Hi Eugene,

tx for the hint. Now, it seems to work.

But i have a Problem with the type property. For attached Messages, i get the value 5. For images, the value is 1.

But for all other attached files (xls, pdf ...) the type propertie is also 1.

Regards

Thomas
Posted 26 Mar, 2012 17:44:50 Top
Eugene Astafiev


Guest


Hi Thomas,

The Outlook Object Model doesn't provide any property or method for such task. Instead, you can get a value of the PR_ATTACH_FLAGS property (comes from Extended MAPI). If the value equals to ATT_INVISIBLE_IN_HTML and
ATT_MHTML_REF your attachment is an embedded image. You can use a low level code or the PropertyAccessor class from the Outlook 2007 Object Model.
Posted 27 Mar, 2012 03:51:30 Top
Thomas Bach


Guest


Hi Eugene,

is there any sample available?

Regards

Thomas
Posted 27 Mar, 2012 07:10:37 Top
Andrei Smolin


Add-in Express team


Posts: 18791
Joined: 2006-05-11
Hi Thomas,

We don't have such a sample. However, we we can develop such a sample project for you because your Premium subscription includes this kind of service. What Outlook versions you need to be supported? And please confirm that your programming language is VB.NET.


Andrei Smolin
Add-in Express Team Leader
Posted 27 Mar, 2012 07:46:11 Top
Thomas Bach


Guest


Hi Andrei,

the Problem is, i Need Support for all Outlook Versions (2003 - 2010). I have no experience with Extended MAPI, so i need some code snippets to understand the concept. (Or some documentation also for beginners with MAPI).

Yes, my programming language is VB.NET. I?m working with VS 2010.

It will be great, if you can help me.

Regards

Thomas
Posted 27 Mar, 2012 08:05:28 Top
Andrei Smolin


Add-in Express team


Posts: 18791
Joined: 2006-05-11
I've started working on the sample porject. Tomorrow, I'll tell you about approximate finish date.


Andrei Smolin
Add-in Express Team Leader
Posted 27 Mar, 2012 09:35:17 Top
Thomas Bach


Guest


Tx
Posted 27 Mar, 2012 09:52:25 Top
Andrei Smolin


Add-in Express team


Posts: 18791
Joined: 2006-05-11
Hi Thomas,

Per your request, I've developed a sample Outlook add-in that scans attachments of an email opened in the active Outlook inspector winodw. The output is seen in the http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx utility.

Please download the sample project here:

Sample add-in name:
adx-ol-get-embedded-attachment-vb
Project:
VS 2005, VB.NET
URL:
http://www.add-in-express.com/files/projects_pub/adx-ol-get-embedded-attachment-vb.zip

About the project.

To determine if an attachment is embedded, you try to get the PR_ATTACH_CONTENT_ID (PR_ATTACH_CONTENT_ID_W) MAPI property. If that property exists, then the attachment is embedded. To get this MAPI property, two methods are used:
- in Outlook 2000-2003, you use Extended MAPI
- in Outlook 2007-2010, you use PropertyAccessor object; this allows supporting Outlook 2010 64-bit in the same add-in

The project is developed with Option Strict On. Although this makes the code "heavier" for a VB developer, this allows converting it easily to CSharp using any free VB.NET-C# convertors available on the web.

Pay attention to releasing COM object. Doing this consistently saves a lot of your time at the debugging phase.


Andrei Smolin
Add-in Express Team Leader
Posted 28 Mar, 2012 08:43:10 Top