Reading Atom feed of gmail account from C#(从 C# 读取 gmail 帐户的 Atom 提要)
问题描述
我有一个项目,它将向 gmail 帐户发送包含某些数据的电子邮件.我认为阅读 Atom 提要可能比通过 POP 连接更容易.
I have a project that will send an email with certain data to a gmail account. I think that it will probably be easier to read the Atom feed rather than connect through POP.
根据谷歌我应该使用的网址是:
The url that I should be using according to Google is:
https://gmail.google.com/gmail/feed/atom
问题/问题是:如何验证我想查看的电子邮件帐户?如果我在 Firefox 中执行此操作,它会使用 cookie.
The question/problem is: how do I authenticate the email account I want to see? If I do it in Firefox, it uses the cookies.
我也不确定如何准确地下载"这个请求应该返回的 XML 文件(我相信正确的术语是流).
I'm also uncertain how exactly to "download" the XML file that this request should return (I believe the proper term is stream).
编辑 1:
我正在使用 .Net 3.5.
I am using .Net 3.5.
推荐答案
这是我在vb.net中使用的:
This is what I used in Vb.net:
objClient.Credentials = New System.Net.NetworkCredential(username, password)
objClient 的类型为 System.Net.WebClient.
objClient is of type System.Net.WebClient.
然后,您可以使用以下方式从提要中获取电子邮件:
You can then get the emails from the feed using something like this:
Dim nodelist As XmlNodeList
Dim node As XmlNode
Dim response As String
Dim xmlDoc As New XmlDocument
'get emails from gmail
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>")
'Get the number of unread emails
xmlDoc.LoadXml(response)
node = xmlDoc.SelectSingleNode("/feed/fullcount")
mailCount = node.InnerText
nodelist = xmlDoc.SelectNodes("/feed/entry")
node = xmlDoc.SelectSingleNode("title")
这在 C# 中应该没有太大的不同.
This should not be very different in C#.
这篇关于从 C# 读取 gmail 帐户的 Atom 提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 C# 读取 gmail 帐户的 Atom 提要


基础教程推荐
- MS Visual Studio .NET 的替代品 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01