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