Reading Atom feed of gmail account from C#

Crash893 picture Crash893 · Jun 13, 2009 · Viewed 14.9k times · Source

I have a project that will send an email with certain data to a gmail account. I think that it will probably be easier to read the Atom feed rather than connect through POP.

The url that I should be using according to Google is:

https://gmail.google.com/gmail/feed/atom

The question/problem is: how do I authenticate the email account I want to see? If I do it in Firefox, it uses the cookies.

I'm also uncertain how exactly to "download" the XML file that this request should return (I believe the proper term is stream).

Edit 1:

I am using .Net 3.5.

Answer

Kirtan picture Kirtan · Jun 13, 2009

.NET framework 3.5 provides native classes to read feeds. This articles describes how to do it.

I haven't used it tho, but there must be some provision for authentication to a URL. You can check that out. I too will do it, and post the answer back.

If you are not using framework 3.5, then you can try Atom.NET. I have used it once, but its old. You can give it a try if it meets your needs.

EDIT: This is the code for assigning user credentials:

XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = new NetworkCredential("[email protected]", "password");

XmlReaderSettings settings = new XmlReaderSettings();
settings.XmlResolver = resolver;

XmlReader reader = XmlReader.Create("https://gmail.google.com/gmail/feed/atom", settings);