1
A
回答
2
这是我开发并用于阅读我的Gmail收件箱的类。
public class GmailClient : IDisposable
{
private const string GmailUri = "https://mail.google.com/mail/feed/atom";
private string _userName;
private string _password;
private GmailList _newMailList;
public GmailClient(string userName, string password)
{
_userName = userName;
_password = password;
}
/// <summary>
/// I'd prefer to return the generic list here instead of using the GetMailItem
/// method to get individual items, but javascript doesn't play nice with generics.
/// </summary>
public void GetUnreadMail()
{
try
{
// Get the XML feed from mail.google.com
XmlElement element = GetFeedXml();
if (element != null)
{
// Deserialize the transformed XML into a generic list of GmailItem objects
XmlNodeReader reader = new XmlNodeReader(element);
XmlSerializer serializer = new XmlSerializer(typeof(GmailList));
_newMailList = serializer.Deserialize(reader) as GmailList;
}
}
catch { }
}
/// <summary>
/// The number of items in the unread mail collection
/// </summary>
public object UnreadMailCount
{
get
{
if (_newMailList != null)
{
return _newMailList.Count;
}
else
{
return 0;
}
}
}
/// <summary>
/// Returns the GmailItem at the specified index
/// </summary>
/// <param name="index">Index if the mail item to return</param>
public GmailItem GetMailItem(int index)
{
if (_newMailList == null || index < 0 || index > _newMailList.Count)
{
throw new IndexOutOfRangeException();
}
return _newMailList[index];
}
/// <summary>
/// Get the XML feed from google and transform it into a deserializable format
/// </summary>
private XmlElement GetFeedXml()
{
try
{
// Create a web request to get the xml feed
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(GmailUri);
request.Method = "GET";
request.Credentials = new NetworkCredential(_userName, _password);
XmlDocument xml = null;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// If the request/response is successful
if (response.StatusCode == HttpStatusCode.OK)
{
// Get the response stream containing the xml
using (XmlTextReader reader = new XmlTextReader(response.GetResponseStream()))
{
// Load the XSLT document (it's an embedded resource)
byte[] data = Encoding.ASCII.GetBytes(GmailReader.Properties.Resources.GmailTransform);
using (MemoryStream xsltStream = new MemoryStream(data))
{
// Create a text reader with the XSLT document
XmlTextReader stylesheetReader = new XmlTextReader(xsltStream);
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(stylesheetReader);
// Run an XSLT transform on the google feed to get an xml structure
// that can be deserialized into a GmailList object
using (MemoryStream ms = new MemoryStream())
{
transform.Transform(new XPathDocument(reader), null, ms);
ms.Seek(0, SeekOrigin.Begin);
xml = new XmlDocument();
// Load the transformed xml
xml.Load(ms);
}
}
}
}
response.Close();
return xml.DocumentElement;
}
catch
{
}
return null;
}
#region IDisposable Members
public void Dispose()
{
// Nothing to do here.
}
#endregion
}}
对不起,我忘了添加1个班,现在是这里....
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace GmailReader
{
[Serializable,
ComVisible(true)]
public class GmailList : List<GmailItem>
{
public GmailList() { }
}
[Serializable,
ComVisible(true)]
public class GmailItem
{
public GmailItem() { }
public string Title;
public string Summary;
public string Link;
public string AuthorName;
public string AuthorEmail;
/*public DateTime Issued;
public DateTime Modified;*/
public string ID;
}
}
4
只需编写一个POP3或IMAP应用程序。这是一个question,它涉及通过IMAP访问GMail。
2
POP3或IMAP协议可以连接到Gmail帐户。 Google还提供只读收件箱Feed API:http://code.google.com/apis/gmail/docs/inbox_feed.html
相关问题
- 1. 在弹出窗口中提交表格
- 2. 在弹出窗口中显示表格
- 3. 窗口/网格中的FlowDocument?
- 4. 在窗口中居中动态生成的表格单元格
- 5. Excel窗口上方的Excel表格
- 6. 什么是JQuery表达式来返回gmail撰写窗口?
- 7. 如何在GMail中实现聊天窗口的弹出功能?
- 8. 删除亲子表格子窗口
- 9. 通过窗口提交html表格
- 10. 通过弹出窗口填写表格
- 11. 表格提交窗口关闭
- 12. PyQt用表格打开子窗口
- 13. VB.NET合并Alt +窗口+拖入表格
- 14. 将Gmail拉入Google表格
- 15. 哪些JavaScript库会处理弹出窗口(即Meebo或Gmail聊天窗口)?
- 16. 在tkinter的窗口中更改表格的位置
- 17. 复制表格中数据的“滑动窗口”的好策略?
- 18. 点击窗口中的网格电话
- 19. 窗口c中的货币格式#
- 20. 窗口文件路径中的空格
- 21. 弹出窗口弹出窗口 - 表格之间的Tab(顺序)不起作用
- 22. 如何使用python在窗口中使用chrome登录到gmail
- 23. 如何在Eclipse RCP的同一窗口中编辑表格行?
- 24. 隐藏PhpStorm数据库工具窗口中的无用表格
- 25. 在MVC中显示表格的jQuery模态窗口
- 26. 在基于窗口的应用程序中创建表格
- 27. 使弹出窗口出现在表格中的超链接上
- 28. 在窗口中的Oracle表格7 jinitiator不能用于IE9
- 29. 将PHP弹出窗口中的数据发布为Smarty表格
- 30. 如何在单独的窗口中打印html表格
这些是什么物品:GmailList,GmailItem,GmailReader? – MAC 2011-02-03 11:40:42