如何实现通过IMAP查看新邮件?
我有一个用Java 实现邮件应用程序的计划。 因此,我有一个关于检查新邮件是否存在的问题。
例如,在《雷鸟》中, 服务器首选项中存在轮询间隔选项。 (默认间隔为 10 分钟。) 但是,雷鸟看起来会在新邮件到来时立即通知。 此行为是相同的,但默认间隔发生变化。
这个间隔是什么意思呢? 并且,如何实现应用程序在收到新邮件时立即通知。 (我是否应该实现应用程序具有轮询检查新邮件是否收到的功能?)
I have a plan to implement mailer application in Java.
Therefore, I have a question about checking the existence of new mails.
For example, in Thunderbird,
Polling interval option exists in server preference.
(default interval is 10 minutes.)
But, thunderbird looks like that it notifies immediately when a new mail comes.
This behaviour is same however default interval changes.
What does this interval mean?
And, how do I implement that the application notifies immediately when a new mail comes.
(Should I implement that an application has polling check funciton whether new mail comes or not?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,当使用 IMAP 时,客户端将连接,查看是否有任何新消息,如果有则处理它们并断开连接,如果不是则断开连接。客户端将在 10 分钟间隔后重试。然而,IMAP中有一个命令叫做IDLE。这基本上表明您希望保持连接打开并在出现新消息时收到通知。该命令在 RFC2177 中定义。
该命令相当简单(来自 RFC2177):
我不确定是否有java 客户端支持这一点,但如果不支持,实现起来将非常简单。您还需要添加一些内容来检查服务器是否支持 IDLE 命令(使用功能),并在发生故障时重新连接。
还值得注意的是,有一些系统,例如 http://cloudmailin.com,允许您以http 帖子。这使您能够获得“实时”响应时间,而无需轮询电子邮件。
By default when using IMAP a client will connect, see if there are any new messages, if there are process them and disconnect and if not just disconnect. The client will then try again after an interval of say 10 minutes. However, there is a command in IMAP called IDLE. This basically states that you wish to keep the connection open and be notified whenever a new message occurs. The command is defined in RFC2177.
The command is fairly simple (from RFC2177):
I'm not sure whether any of the java clients support this but if not it would be quite trivial to implement. You'd also need to add something to check that the server supports the IDLE command (using capabilities) and also to reconnect should a failure occur.
It's also worth noting that there are systems such as http://cloudmailin.com that allow you to receive your email as an http post. This gives you the benefit of having a 'live' response time without having to poll for the email at all.