I was in need of retrieving the unread messages from our email (we are using Google Apps). So I started to search how to do this. I found that Google offers an inbox feed. That was great! The problem was that I had never consumed a feed before.
I searched for documentation on how to do this and I found a sample code that consumes the Gmail feed. It was written in C#. We have our web app developed with VB.NET, so I had to translate the code. It was not working for me (probably I wasn't translating it well), so I just modified the sample code (though most of it is just the translation).
I'm going to post the whole thing, I mean, not only the part when we consume the atom feed, but how to convert and display the information we got. In this case, I'm using a
DataList control. Let's take a look at the code.
First, our HTML with the
DataList where we'll show our Unread Messages (It has just three columns to show the following fields:
Second, the call to the class that will read the Atom Feed, and how we convert what this class returns to fill our
DataList. (I just commented the fields that I don't want to show, if you want to use them, go ahead!)
The code is simple, we instantiate the class
GmailAtomFeed passing the email address and its password to the constructor. We call the
GetGmailAtom function which returns an XML, and we pass it to a
Dataset with one
Datatable which will be bound to the
Third, the class itself that reads the Atom Feed:
And that's it. Please feel free to leave any comments, suggestions or questions. As I said, this is based on the sample code that I linked before in this post but with a small modification in the
GmailAtomFeed class and a different output.
Hope it helps!