简体   繁体   English

如何使用java socket通过imap从gmail中读取邮件

[英]how to read mails from gmail with imap by using java socket

I'm kinda interested in with java sockets in these days and i want to read my mails from gmail with using java socket. 这些天我对java套接字感兴趣,我想使用java socket从gmail中读取我的邮件。 is it possible? 可能吗?

Socket s;
s = new Socket("imap.gmail.com", 993);
InputStream in;
in = s.getInputStream();
BufferedReader sin = new BufferedReader(new InputStreamReader(in));
PrintWriter output = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
String line;
output.println("a001 LOGIN my-e-mail my-pass");
output.flush();
while ((line = sin.readLine()) != null)
System.out.println(line);
s.close();

what should i do after connecting to socket? 连接插座后我该怎么办?

thanks in advance. 提前致谢。 (notice: i dont want to use java mail api, things get really easy with it, i'm just choosing this way to get familiar what's going on behind the scene) (注意:我不想使用java邮件api,事情变得非常简单,我只是选择这种方式来熟悉幕后发生的事情)

edited the code. 编辑了代码。

If you feel like getting familiar with IMAP at GMail, you're going to have to put SSL/TLS on top of it. 如果您想在GMail熟悉IMAP,那么您将不得不将SSL / TLS置于其上。 All GMail traffic is encrypted. 所有GMail流量都已加密。

Once you have a socket you implement the IMAP protocol on it. 有了套接字后,就可以在其上实现IMAP协议。

http://tools.ietf.org/html/rfc3501 http://tools.ietf.org/html/rfc3501

+1 for the question. 这个问题的+1。

EDIT: Yes, it is possible to speak to IMAP server using java sockets and in some cases it might be advisable to do so rather than using java mail library. 编辑:是的,可以使用java套接字与IMAP服务器通信,在某些情况下,建议这样做而不是使用java邮件库。

Using javamail is the easy way out. 使用javamail是一种简单的方法。 It is also appears to be the obvious solution but, there are cases when you do not want to go that route. 它似乎也是一个明显的解决方案,但是,有些情况下你不想走那条路。

Javamail is highly unsuiatble for scaled out deployments with a large number of concurrent users that need to be kept notified on near real time basis. 对于需要近乎实时地通知大量并发用户的扩展部署,Javamail非常难以理解。

Say, you want to service more than 1000 users per jvm and want to keep the overhead of creating imap connections low then, you will resort to implementing sockets yourself and write IMAP commands in the socket itself. 比如,你想为每个jvm服务超过1000个用户,并且想要保持创建imap连接的开销低,那么你将自己实现套接字并在套接字本身中编写IMAP命令。 Needless to say, other benefits include near instantaneous delivery of a new email to your user ie if you are using AJAX. 毋庸置疑,其他好处包括即时向您的用户发送新电子邮件,即如果您使用的是AJAX。

Near instantaneous email is one of the few things left to like about Blackberry. 近乎即时的电子邮件是关于黑莓的少数几件事情之一。 Given RIMs scale, I don't think they would be using Javamail on top of IMAP to push out emails. 鉴于RIM规模扩大,我认为他们不会在IMAP上使用Javamail来推送电子邮件。 That would be highly non-performant. 这将非常不具备性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM