Reputation: 6872
I'm trying to find some code that will allow me to suck out every email in my Gmail account, it seems that the code currently out there using Atom reader only reads unread messages.
I want to read everything, subjects, body and attachments.
Is it possible, does anyone have some working code.
Dave
Upvotes: 0
Views: 1166
Reputation: 14780
Learn how to read information from XML and you can get every information you want on Gmail from this feed https://mail.google.com/mail/feed/atom. I have one sample code below which reads the number of unread messages and reads the title and summary, but you can get another information like from who, attachments, ect. No extra libraries needed :)
try
{
System.Net.WebClient objClient = new System.Net.WebClient();
string response;
string title;
string summary;
//Creating a new xml document
XmlDocument doc = new XmlDocument();
//Logging in Gmail server to get data
objClient.Credentials = new System.Net.NetworkCredential("Email", "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 of emails
nr = doc.SelectSingleNode(@"/feed/fullcount").InnerText;
//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 exe)
{
MessageBox.Show("Check your network connection");
}
Upvotes: 0
Reputation: 5950
Your best bet, as others have noted, is using the IMAP protocol. Note, however, that the Google IMAP implementation requires a secure connection, so it is not just a matter of implementing IMAP.
There is a C# implementation here, which also includes the secure connection stuff, but beware that there are quite a few bugs in it, concerning things like header-encoding and others, so be prepared to fix a few bugs if you decide to use it.
Upvotes: 0
Reputation: 6489
What you have want to do is not a simple application that we can help you out to write a mail client application, It needs a lots of effort to read many articles about how POP3 or IMAP mail clients work also you have to understand RFC 1939 and RFC 1081 documents related to these protocols. Anyway You have to use IMAP or POP3 protocols to implement you mail client application there are many articles outside which you can refer to them.
And RFC Documents :
Upvotes: 1
Reputation: 3185
You can do this via e.g. IMAP. It should be enabled at the account settings though.
There are numerous C# tutorials about using/implementing IMAP, just google for them.
Upvotes: 0