Introduction

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:

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

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:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Security.Principal;
  8. using System.Net;
  9. using System.Collections;
  10. using System.IO;
  11. using System.Xml;
  12. using System.Data;
  13. public partial class _Default : System.Web.UI.Page
  14. {
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. }
  18. protected void showdet(object sender, EventArgs e)
  19. {
  20. NewMethod();
  21. login.Visible = false;
  22. }
  23. private void NewMethod()
  24. {
  25. var Url = @"https://mail.google.com/mail/feed/atom";
  26. var username = TextBox1.Text.Trim();
  27. var password = TextBox2.Text.Trim();
  28. var encoded = TextToBase64(username + ":" + password);
  29. var request = HttpWebRequest.Create(Url);
  30. request.Method = "POST";
  31. request.ContentLength = 0;
  32. request.Headers.Add("Authorization", "Basic" + encoded);
  33. var respone = request.GetResponse();
  34. var stream = respone.GetResponseStream();
  35. XmlReader reader = XmlReader.Create(stream);
  36. XmlDocument doc = new XmlDocument();
  37. doc.Load(reader);
  38. doc.Save(Server.MapPath("GmailFeed.xml"));
  39. DataSet dt = new DataSet();
  40. // dt.ReadXmlSchema(Server.MapPath("GmailFeed.xml"));
  41. dt.ReadXml(Server.MapPath("GmailFeed.xml"));
  42. DataTable DT = dt.Tables[3];
  43. // DT.Merge(dt.Tables[1]);
  44. DT.Merge(dt.Tables[2]);
  45. grid.DataSource = DT;
  46. DataBind();
  47. Session["Table"] = DT;
  48. }
  49. public static string TextToBase64(string S)
  50. {
  51. System.Text.ASCIIEncoding encode = new System.Text.ASCIIEncoding();
  52. byte[] bytes = encode.GetBytes(S);
  53. return System.Convert.ToBase64String(bytes, 0, bytes.Length);
  54. }
  55. protected void IndexChagning(object sender, GridViewPageEventArgs e)
  56. {
  57. grid.PageIndex = e.NewPageIndex;
  58. if (!object.Equals(Session["Table"], null))
  59. {
  60. grid.DataSource = Session["Table"] as DataTable;
  61. DataBind();
  62. }
  63. }
  64. }

Output

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

Gmail-Atom-Feed-In-Asp.net.png



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

Atom-Feed-of-gmail-account-in-asp.net.png