Windows 窗体中的 Gmail

发布于 2024-10-15 20:05:44 字数 80 浏览 1 评论 0原文

谷歌是否提供任何用于在 Windows 应用程序中获取电子邮件的服务。如果没有,请给我一个关于开发相同内容的简短描述。

提前致谢。

Is there any services providing by google for getting emails in a windows application. If not, please give me a breif description for developing the same.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

踏月而来 2024-10-22 20:05:44

只需编写一个 POP3 或 IMAP 应用程序即可。这是一个问题处理通过 IMAP 访问 GMail。

Just write a POP3 or IMAP application. Here's a question that deals with accessing GMail via IMAP.

静谧幽蓝 2024-10-22 20:05:44

这是我开发并用来读取我的 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;
}

}

This is the class which i develop and used to read my gmail Inbox.

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
}}

Sorry i forgot to add 1 more class it is here now....

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;
}

}

唠甜嗑 2024-10-22 20:05:44

POP3 或 IMAP 协议可以连接到 Gmail 帐户。 Google 还提供了只读收件箱供稿 API:http://code.google。 com/apis/gmail/docs/inbox_feed.html

POP3 or IMAP protocols can connect to a Gmail account. Google also provides a read-only inbox feed API: http://code.google.com/apis/gmail/docs/inbox_feed.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文