none
Read inbox using Exchange 2010 and VB .NET RRS feed

  • General discussion

  • Hi ,

    I'm using VS 2010 and Exchange 2010.I haven't installed the SP1 yet.

    Anyway.

    I'm trying to get Inbox messages that I have already read and do some process .

    So what I did was this.

    ServicePointManager.ServerCertificateValidationCallback = New _
               RemoteCertificateValidationCallback(AddressOf CertificateValidationCallBack)
          Dim Myexchange As New ExchangeService(ExchangeVersion.Exchange2010)
          Dim myversion As New ExchangeVersion
    
          Myexchange.Credentials = New NetworkCredential("test", "test", "MyIP")
          Myexchange.Url = New Uri("https://myip/EWS/Exchange.asmx")
    
     Dim view As New ItemView(10)
          ' Return only ten items.
          view.SearchFilter = New SearchFilter.SearchFilterCollection(LogicalOperator.[And], New SearchFilter.IsEqualTo(ItemSchema., Importance.High), New SearchFilter.ContainsSubstring(ItemSchema.Subject, "API"))
          Dim findResults As FindItemsResults(Of Item) = Myexchange.FindItems(WellKnownFolderName.Inbox, view)
    
    
    
          Dim inbox As Folder = Folder.Bind(Myexchange, WellKnownFolderName.Inbox)
          inbox.FindItems(view)
    

    The thing is that I found the code and tried to customize it to my needs.

    So I have a couple of questions.

    1.How can I retrieve the email messages from Inbox which status is read ? Can anyone give me a sample code ?

    2. In all the examples that I viewed I saw that you must declare the size of the ItemView. For eg get me 10 or 20 records etc. I don't want that.

    I need to tell my app to read everything I have in my Inbox or the Sent Items folder. How can I do that in VB .Net ?

    Any help would be mostly appreciated.

    thank you in advance

     

     

    Wednesday, July 27, 2011 12:00 PM

All replies

  • Hi,

    1) Add an IsEqualTo searchfilter for the property EmailMessageSchema.IsRead set to false:
    New SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, true)

    2) Don't retrieve all at once. It's better to read the items in batches: Read first 0-511, then 512-1024, etc.

    Kind regards,
    Henning

    Wednesday, July 27, 2011 12:17 PM
  • Hi and thank you for your response.

    And where should I put this searchfilter ?

    Just saw that ItemView doesn't have SearchFilter Method.

     

    thank you

    Thursday, July 28, 2011 8:01 AM
  • Hi,

    you can pass it to the FndItems method.

    Kind regards,
    Henning

    "zakkar" wrote in message news:90add07f-bb2e-463c-a8c1-014531da0767@communitybridge.codeplex.com...

    Hi and thank you for your response.

    And where should I put this searchfilter ?

    Just saw that ItemView doesn't have SearchFilter Method.

    thank you

    Thursday, July 28, 2011 8:42 AM
  • Hi ,

    Found it .

     Dim InboxFolder As New Folder(Myexchange)
            InboxFolder = Folder.Bind(Myexchange, WellKnownFolderName.Inbox)
            Dim SearchFilter As New SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, True)
    
    
            Dim view As New ItemView(InboxFolder.TotalCount) _
              With {.PropertySet = New PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, _
                          ItemSchema.DateTimeReceived)}
    
    
    
            view.OrderBy.Add(ItemSchema.DateTimeReceived, Microsoft.Exchange.WebServices.Data.SortDirection.Ascending)
            ' view.PropertySet = New PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, ItemSchema.DateTimeReceived, ItemSchema.Body)
    
            Dim findResults As FindItemsResults(Of Item)
            Dim mystring As String
    
            Do
              findResults = Myexchange.FindItems(WellKnownFolderName.Inbox, SearchFilter, view)
    
              ' Do something with the item.
              For Each item As Item In findResults.Items
    
                mystring = item.Subject
    
    
              Next
    
              view.Offset += 50
            Loop While findResults.MoreAvailable

    thank you

     

    Friday, July 29, 2011 6:31 AM