繁体   English   中英

从C#读取整个GMail

[英]Read Entire GMail from C#

我正在尝试查找一些代码,这些代码将使我能够吸收Gmail帐户中的每封电子邮件,似乎当前使用Atom阅读器提供的代码只能读取未读邮件。

我想阅读所有内容,主题,正文和附件。

有没有可能有人有一些有效的代码。

戴夫

您想要做的不是一个简单的应用程序,我们可以帮助您编写一个邮件客户端应用程序,它需要大量的精力来阅读许多有关POP3或IMAP邮件客户端如何工作的文章,并且您还必须了解RFC 1939和与这些协议有关的RFC 1081文档。 无论如何,您必须使用IMAP或POP3协议来实现您的邮件客户端应用程序,您可以参考很多文章。

SMTP和POP3邮件服务器

C#.NET中的POP3客户端

和RFC文件:

邮局协议

了解如何从XML读取信息,并可以从此供稿https://mail.google.com/mail/feed/atom获得有关Gmail的所有信息。 我下面有一个示例代码,该代码读取未读邮件的数量并读取标题和摘要,但是您可以从诸如谁,附件等中获得另一信息。 不需要额外的库:)

        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");
    }

您可以通过例如IMAP做到这一点。 不过应该在帐户设置中启用它。

有关使用/实现IMAP的大量C#教程,仅适用于Google。

正如其他人所指出的,最好的选择是使用IMAP协议。 但是请注意,Google IMAP实现需要安全的连接,因此这不仅仅是实现IMAP的问题。

有一个C#实现在这里 ,其中还包括了安全连接的东西,但要注意的是,中间有不少错误,将来的事,像头编码和其他人,所以要准备修复一些bug,如果你决定使用它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM