Getting Gmail Unread Email Through Atom Feed in ASP.NET


Atom makes it easy to receive regular updates from news websites, blogs, and/or Gmail. This feed is only available for Gmail accounts on Google Apps domains.

To get a Gmail Feed, you can access the Atom Feed for your Gmail account on the following URL:

Enter your Gmail account credentials and access the Atom Feed for all unread Email.

Note: Gmail messages will appear in your aggregator only if there are unread messages in your account inbox.

The following C# code shows how to read/save the atom feed of that account after a valid authentication process:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Principal;
using System.Net;
using System.Collections;
using System.IO;
using System.Xml;
using System.Data; 

public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
protected void showdet(object sender, EventArgs e)
        login.Visible =

    private void NewMethod()
var Url = @"";
var username = TextBox1.Text.Trim();
var password = TextBox2.Text.Trim();
var encoded = TextToBase64(username + ":" + password);
var request = HttpWebRequest.Create(Url);
        request.Method =
         request.ContentLength = 0;
"Authorization", "Basic" + encoded);
var respone = request.GetResponse();
var stream = respone.GetResponseStream();
XmlReader reader = XmlReader.Create(stream);
XmlDocument doc = new XmlDocument();
DataSet dt = new DataSet();
        // dt.ReadXmlSchema(Server.MapPath("GmailFeed.xml"));
DataTable DT = dt.Tables[3];      
       // DT.Merge(dt.Tables[1]);
        grid.DataSource = DT;
"Table"] = DT;

    public static string TextToBase64(string S)
ASCIIEncoding encode = new System.Text.ASCIIEncoding();
byte[] bytes = encode.GetBytes(S);
return System.Convert.ToBase64String(bytes, 0, bytes.Length);

protected void IndexChagning(object sender, GridViewPageEventArgs e)
        grid.PageIndex = e.NewPageIndex;
if (!object.Equals(Session["Table"], null))
             grid.DataSource = Session[
"Table"] as DataTable;


Enter Email and Password for your account and click on the button.

You will see that all the new or unread message from your account inbox will appear.