This blog is subject the DISCLAIMER below.

Friday, September 11, 2009

Reading Atom feed of Gmail inbox via C#



Today I am coming with Gmail feature that may be useful although many people don't know and how to access it via simple C# code.
Gmail Atom feed is xml format file to know the unread messages .

http://mail.google.com/mail/feed/atom/ shows the most recent unread items from your inbox. Gmail also offers feeds for your labels:http://mail.google.com/mail/feed/atom/labelname/ .
To know the feature in detials go to this link @ (the unofficial news and tips about Google).

As a developer you can download the C# example here.
All what you need is create instance a simple class called GmailHandler and drop this lines in your project.


//just 2 steps to get your Gmail Atom
//1- Create the object from GmailHandler class
GmailHandler gmailFeed = new GmailHandler("WriteHereYourGmailUserName(ex: fci-h)", "WriteHereYourGmailPassword(ex: XXX)");
//2-get the feed :) ,Congratulations
XmlDocument myXml = gmailFeed.GetGmailAtom();


Just happy code :)

13 comments:

Mohamed Gamal El-Din said...

Thank you so much. Very helpful

xandercoded said...

Good post, thanks for revealing this functionality

Mohammed Hewedy said...

What is the namespace in which this class resides ?

suresh kumar said...

I read the xml values to dataset by dataset.ReadXml(new XmlNodeReader(myXml));

now I have 4 tables in dataset. Table 3 contains about message summary and title and table 4 contains where the message comes from ie sender address...how will i combine this both one.
ie i need to bind the grid like below.

sender subject message date

Looking forward your response.

Ahmed Essawy said...

Dear suresh kumar,

regarding to what you need :
sender subject message date

sender: Table[3].Colomn["email"]
subject: Table[2].Colomn["title"]
message:Table[2].Colomn["summary"]
date: Table[2].Colomn["issued"]

you can combine them in new DataTable or any data type that the datagrid accepts.

keep in mind that here is a summery of the message not the whole(complete) one.

balaji said...

iam getting the unread mails correctly but the body content is not coming fully only 100 chars coming ..what to do..

Ahmed Essawy said...

@balaji
regarding to the body of the mail just first 100 characters are accessible not the whole(complete) body.

Anonymous said...

How to read complete body of message?

Ahmed Essawy said...

Atom feed of Gmail is not to view the full email !!

below is other post that I have written for issue like this, that may help you.
http://fci-h.blogspot.com/2009/09/reading-pop3-secure-ssl-like-gmail-via.html

bhanu said...

hi plz help me adding the xml file to dataset..i want toassign taht datset to gridview...

shuaib said...

hi,i am new to .net.i would like to run your code.can you direct me how to please?

Anonymous said...

Dear Ahmed,

Thank you so much. Very helpful

I have one question: Once i getting UNREAD mails then it will change to READ mails. because every minutes i want to check unread mails. if its possible please let me know the process..

Santhosh Kumar said...

Thanks for the code, but i want to retrieve the attachment,how can this be implemented.