如何在C#windows应用程序中从gmail下载电子邮件 [英] How to download emails from gmail in C# windows application

查看:69
本文介绍了如何在C#windows应用程序中从gmail下载电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮我从C#windows应用程序中的gmail帐户下载电子邮件。

感谢您的宝贵帮助。





我还需要一个帮助。当我每次尝试下载时,所有邮件都会被下载。我如何限制下载尚未下载的邮件?

解决方案

就像将电子邮件发送到服务器进行传递一样,使用协议(SMTP ; 简单邮件传输协议 [ ^ ]),以同样的方式从服务器下载需要类似协议的电子邮件; IMAP; 互联网邮件访问协议 [ ^ ]。



.NET框架或Windows窗体应用程序中没有内置函数可供使用您可以使用IMAP协议直接向服务器发送命令。所以,要么你需要使用第三方插件;我也使用过,我认为你会喜欢这个库, ImapX [ ^ ]。否则,您可以使用TCP / IP流并将请求直接发送到服务器并使用响应(不是一个好主意;使用库)。



As已在评论中提及,您还可以使用 Gmail的REST API [ ^ ](仅适用于Gmail; off-gmail服务器不起作用)来获取消息, JSON格式的线程和草稿等。但它不会像ImapX库那样强大和强大,因为ImapX支持IDLE事件;让你在收到消息后下载消息;喜欢推送通知。


除了解决方案1:



您可以找到IMAP和Gmail设置的详细信息POP3: https://support.google.com/mail/troubleshooter/1668960 [ ^ ]。



如果你想使用POP3,我会推荐OpenPOP.NET:

http://openpop.net [< a href =http://openpop.nettarget =_ blanktitle =New Window> ^ ],

http://sourceforge.net/projects/hpop [ ^ ]。

它不仅实现了POP3协议。它的主要作用是解析邮件消息。我对这段代码的质量不太满意,所以我只把它作为参考,这是非常宝贵的,因为它彻底考虑并记录了这些标准的使用。电子邮件中涉及太多标准文档,尤其是MIME类型。



因此,即使使用IMAP,也可以使用OpenPOP.NET。 br />


如果你想使用IMAP,那么查看简单的客户端样本会很有用:https://code.msdn.microsoft.com/windowsdesktop/Simple-IMAP-CLIENT-b249d2e6 [ ^ ]。

您可以获取一组邮件组件,包括来自微软的IMAP,POP3等等: https://visualstudiogallery.msdn.microsoft .com / 28b96cd4-b755-48a0-b686-9abb7d5607a8 [ ^ ]。



此CodeProject文章也很有用: IMAP和C#中的POP3客户端 [ ^ ]。



-SA


http://rfinochi.github.io/pop3dotnet/



您可以使用图书馆目前在Pop3dotnet。他们有几个功能,包括下载你的电子邮件的功能。



如果你是一个Nuget情人你总能找到这个dll列在那里

Can anyone help me in downloading emails from my gmail account in C# windows application.
Thanks to all for your valuable help.


I need one more help. When i try to download each time, all mails are getting downloaded. How can i restrict to download the mails which I haven't downloaded yet?

解决方案

Just as to send the emails to the server for delivery a protocol is used (SMTP; Simple mail transfer protocol[^]), in a same manner, to download the emails from the server you require a similar protocol; IMAP; Internet message access protocol[^].

There are none built-in functions in .NET framework or Windows forms applications to let you directly send commands to a server using IMAP protocol. So, either that you need to be using a third-party plugin; which I have also used and I think you would love that library, ImapX[^]. Otherwise, you can use the TCP/IP streams and send requests directly to the server and work with the response (Not a good idea; use the library).

As already mentioned in the comments, you can also use the REST API of Gmail[^] (which will work with Gmail only; off-gmail servers won't work) to fetch messages, threads and drafts etc in a JSON format. But it won't be as much strong and powerful as much that ImapX library is, because ImapX supports IDLE events; letting you download the messages as they are recieved; like a push-notifications.


In addition to Solution 1:

You can find the detail of Gmail settings for IMAP and POP3 here: https://support.google.com/mail/troubleshooter/1668960[^].

If you want to use POP3, I would recommend OpenPOP.NET:
http://openpop.net[^],
http://sourceforge.net/projects/hpop[^].
Not only it implements POP3 protocol. Its main role is to parse mail messages. I wasn't quite satisfied with the quality of this code, so I used it only as a reference, which was invaluable, as it thoroughly takes into account and document the use of those standards. There are well too many standard documents involved in e-mail, especially in MIME types.

So, it's good to use OpenPOP.NET even if you use IMAP.

If you want to use IMAP, it would be useful to look at the simple client sample: https://code.msdn.microsoft.com/windowsdesktop/Simple-IMAP-CLIENT-b249d2e6[^].
You can obtain a set of mail components, including IMAP, POP3 and a lot more, from Microsoft: https://visualstudiogallery.msdn.microsoft.com/28b96cd4-b755-48a0-b686-9abb7d5607a8[^].

This CodeProject article can also be useful: IMAP and POP3 Clients in C#[^].

—SA


http://rfinochi.github.io/pop3dotnet/

You can use libraries present in the Pop3dotnet.They have several features which includes a function for downloading your e-mails.

If you are a Nuget lover you can always find this dll listed there.


这篇关于如何在C#windows应用程序中从gmail下载电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆