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 提要
基础教程推荐
- JSON.NET 中基于属性的类型解析 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
