posts - 36 , comments - 2 , trackbacks - 0

Integrate Apps with Gmail (.NET or Java).

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

The RSSBus 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 RSSBus 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 RSSBus 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);
    enableMailBoxSelected(true);
    refreshMailList(data);
    }
    Now we can add our search terms to the WHERE clause.
  • Step 7: For simple searches, such as seraching 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 |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 

Powered by: