【问题标题】:Read Entire GMail from C#从 C# 读取整个 GMail
【发布时间】:2013-08-22 06:42:15
【问题描述】:

我正在尝试找到一些代码,让我可以读取我的 Gmail 帐户中的每封电子邮件,目前使用 Atom 阅读器的代码似乎只能读取未读邮件。

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

有可能吗,有没有人有一些工作代码。

戴夫

【问题讨论】:

标签: c# gmail email-client


【解决方案1】:

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

SMTP and POP3 Mail Server

A POP3 Client in C# .NET

和 RFC 文档:

Post Office Protocol

【讨论】:

  • 感谢大家的回复,我看看能不能在接下来的几天里让它工作,如果可以的话,发布一个工作代码示例
【解决方案2】:

您可以通过例如地图。不过,它应该在帐户设置中启用。

有很多关于使用/实现 IMAP 的 C# 教程,只需 google 即可。

【讨论】:

    【解决方案3】:

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

    有一个 C# 实现 here,它还包括安全连接的内容,但要注意其中有很多错误,例如标头编码和其他内容,因此请准备好修复一些错误,如果你决定使用它。

    【讨论】:

      【解决方案4】:

      了解如何从 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");
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-11
        • 1970-01-01
        • 1970-01-01
        • 2018-10-04
        • 2011-10-26
        • 1970-01-01
        相关资源
        最近更新 更多