从 C# 读取 gmail 帐户的 Atom 提要

Reading Atom feed of gmail account from C#(从 C# 读取 gmail 帐户的 Atom 提要)
本文介绍了从 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 提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)