posts - 88 , comments - 3 , trackbacks - 0

Integrate Apps with Gmail (.NET or Java).

Use the CData Google ADO.NET Provider or JDBC Driver to read and search email messages on your Gmail accounts.

The CData Google Data Provider for ADO.NET allows you to use the search capabilities in IMAP to query your Gmail account. This article will explore how to execute your own custom queries from your application. We will use the CData Google Data Provider along with the Google Email demo to execute custom queries on a Gmail account.

  • Step 1: Navigate to the \demos - winform\googlemail\ folder in your installation directory and open either the C# or VB version of the demo. This article will use the C# version.
  • Step 2: Build and run the demo. Enter your credentials and click the Connect button.
  • Step 3: After connecting, the left-hand panel directly below the credentials will be populated with the available mailboxes associated with your Gmail account. Selecting a mailbox will retrieve the individual messages contained.
  • Step 4: The Advanced Search Options panel contains fields that allow you to search based on a number of different simple search criteria. You can search using as many of these criteria at one time as you like.
  • Step 5: Now, we will show off the powerful capabilities of the CData Google Data Provider. The Data Provider contains a number of columns that let you refine your search to exactly fit what you need. More importantly, you can query based on multiple search criteria allowing you to easily create complex queries. To see this in action, we'll edit the demo code to update the query.
  • Step 6: For the purposes of demostration, we will hard-code the query we want to run. In the listSelectedMailbox() function, modify the query before you pass it to the GoogleDataReader object like so:
    using (GoogleConnection conn = new GoogleConnection(buildConnectionString())) {
    Query = "SELECT Id,From,Subject,Date,Size,Attachments FROM MailMessages WHERE () AND Mailbox=Inbox";
    GoogleDataReader data = executeCommand(conn, Query, nullnull);
    Now we can add our search terms to the WHERE clause.
  • Step 7: For simple searches, such as searching for all emails from a particular person, you can use the standard Columns in your WHERE clause. For example, searching for all emails from Twitter in our Inbox from a certain date, we can use the query: 
    SELECT * FROM MailMessages
    WHERE (FROM='Twitter' AND Date > '11-25-2012')
    AND Mailbox=Inbox

  • Step 8: To run the query, simply start the demo again and click on your Inbox. Only emails that match the criteria you specified will be returned.

  • For a look at more advanced queries see: Using SQL to query Gmail

Print | posted on Thursday, December 20, 2012 2:08 AM | Filed Under [ .net google cdata jdbc gmail google apps IMAP ]


No comments posted yet.
Post A Comment

Powered by: