-1

I am using below code to read the emails from gmail. But the problem is it gives email which are unread. In my case I want to read the last 04 emails irrespective of it has been read or unread

class ReadEmail
    {
        public void AccessEmail(string userName, string password)
        {
            try
            {
                System.Net.WebClient objClient = new System.Net.WebClient();
                string response;
                string title;
                string summary;

                //Creating a new xml document
                XmlDocument doc = new XmlDocument();
                XmlNode nr = default(XmlNode);

                //Logging in Gmail server to get data
                objClient.Credentials = new System.Net.NetworkCredential(userName, password);
                //reading data and converting to string
                response = Encoding.UTF8.GetString(
                           objClient.DownloadData(@"https://mail.google.com/mail/feed/atom"));

                response = response.Replace(
                     @"<feed version=""0.3"" xmlns=""http://purl.org/atom/ns#"">", @"<feed>");

                //loading into an XML so we can get information easily
                doc.LoadXml(response);


                nr = doc.SelectSingleNode(@"/feed/fullcount");

                //Reading the title and the summary for every email
                foreach (XmlNode node in doc.SelectNodes(@"/feed/entry"))
                {
                    title = node.SelectSingleNode("title").InnerText;
                    summary = node.SelectSingleNode("summary").InnerText;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex.Message);
            }


        }

Further complete email body I cannot see with the above code.

Shabar
  • 2,617
  • 11
  • 57
  • 98

1 Answers1

1

The gmail atom feed will only give you a summary of your emails. If you need the complete body you have to use another protocol, like POP3 or iMap.

Here's an answer that shows you how to do that: Count number of emails in gmail using IMAP

Community
  • 1
  • 1
Mikael Nitell
  • 1,069
  • 6
  • 16