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




Posts: 89
Joined: 2009-10-15
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
Thomas Bach
Posted 26 Mar, 2012 13:27:37 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
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 When to release COM objects in Office add-ins developed in .NET article on our technical blog.

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




Posts: 89
Joined: 2009-10-15
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
Thomas Bach
Posted 26 Mar, 2012 17:44:50 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
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.
.NET, Extended MAPI, Windows Phone & RT
Posted 27 Mar, 2012 03:51:30 Top
Thomas Bach




Posts: 89
Joined: 2009-10-15
Hi Eugene,

is there any sample available?

Regards

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


Add-in Express team


Posts: 14115
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.

Regards from Belarus (GMT+3),

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




Posts: 89
Joined: 2009-10-15
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. Im working with VS 2010.

It will be great, if you can help me.

Regards

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


Add-in Express team


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

Regards from Belarus (GMT+3),

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




Posts: 89
Joined: 2009-10-15
Tx
Thomas Bach
Posted 27 Mar, 2012 09:52:25 Top
Andrei Smolin


Add-in Express team


Posts: 14115
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 DebugView 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.

Regards from Belarus (GMT+3),

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