We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ExchangeMessageInfo object does not populate Attachments property

Hi,
I'm using Aspose.Email libraries to read emails from an Exchange server 2003.
I need to find emails with a specific attachement (named myAttachment.xml).

This is my code:

Const mailboxUri As String = "http://myExchange2003Server/exchange/myUser"
Const username As String = "myUser"
Const password As String = "myPassword"
Const domain As String = "myDomain"

Sub test()

Try
' Create instance of ExchangeClient class by giving credentials
Dim credential As NetworkCredential = New NetworkCredential(username, password, domain)
Using client As ExchangeClient = New ExchangeClient(mailboxUri, credential)

' Call ListMessages method to list messages info from Inbox
Dim msgCollection As ExchangeMessageInfoCollection = client.ListMessages(client.MailboxInfo.InboxUri)
Debug.WriteLine("Total messages: " & msgCollection.Count.ToString)

' Loop through the collection to display the basic information
For Each msgInfo As ExchangeMessageInfo In msgCollection
If msgInfo.HasAttachments Then
Debug.WriteLine("==================================")
Debug.WriteLine("Email with attachemnts:")
Debug.WriteLine("Subject: " & msgInfo.Subject)
Debug.WriteLine("Attachments count: " & msgInfo.Attachments.Count.ToString())
End If
Next msgInfo


End Using
Catch ex As Exception
addMessage(ex.Message)
End Try
End Sub

And the output is:

Total messages: 15
==================================
Email with attachemnts:
Subject: Hello World
Attachments count: 0
==================================
Email with attachemnts:
Subject: Email test number 1
Attachments count: 0

As you can see, even if the flah HasAttachments is true, the Attachments list is empty. I've seen that if I call the FetchMessage method all attachments are downloaded...
but if I call that method I obtain 2 undesired side effects:
1) I download the message body (I don't need to read the body of the message)
2) I downalod all attachments, even if I want do download the only attachment file with name myAttachment.xml"

Is there a better way to obtain my goal?
Thank you

Hi Alessandro,


Thank you for writing to us.

After testing this issue with the latest version of Aspose.Email for .NET 2.9.0, I was able to observe this issue. The ExchangeAttachmentInfo is not populated even if there are attachments with the message. I have logged this issue in our issue tracking system as NETWORKNET-33790 for further investigation by our development team, and will update you here once any information is available in this regard.

Hi Alesssandro,


We have analyzed the issue in detail and found that its not a bug. Actually fetching attachments is a heavy operation while message info collection is obtained. That’s why this is an optional operation and can be set to retrieve attachments information as given below:

'Change following line of code in your sample
'Dim msgCollection As ExchangeMessageInfoCollection = client.ListMessages(client.MailboxInfo.InboxUri)
Dim msgCollection As ExchangeMessageInfoCollection = client.ListMessages(client.MailboxInfo.InboxUri, -1, ExchangeListMessagesOptions.FetchAttachmentInformation)

Could you please give a try to the above sample code and share the feedback with us?

Thanks for your cooperation and understanding.

I’ve tried that code and it works.

But, unfortunately, from a mailbox with many email messages it requires a long time to execute.
Thank you anyway.


Hi Alesssandro,


Thank you for the feedback.

I agree with you here, but as I mentioned earlier fetching attachments information is a heavy operation and will take time. In any case, I hope using the suggested option can solve your problem. Please feel free to write back to us in case you have any other query/inquiry related to Aspose.Email. We’ll be glad to assist you further.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan