当我有很多帐户时,如何查询IMAP服务器中的新邮件 [英] How to query IMAP server for new mails when I have lots of accounts
问题描述
现在,我想编写一个程序(守护程序)以向IMAP服务器查询新邮件,并在新邮件到达时通知客户端.我有成千上万的电子邮件帐户,所以我想知道如何高效,轻松地完成此操作.
Now, I want to write a program(daemon) to query IMAP server for new mails and notify clients when their new mails arrive. And I have thousands of email accounts, so I want to know how to accomplish this efficiently and easily.
据我了解,我知道两种可能的解决方案.
From my understanding, I know two possible solutions.
- 一种民意调查"风格的电子邮件帐户查询
- 使用IMAP空闲扩展名和事件驱动的I/O(epoll)我想知道两种解决方案的优缺点.
I want to know the advantages and disadvantages of both solutions.
我还想知道是否有任何库(C,C ++,PHP,Python)可以帮助我完成此类工作.或者我怎么能自己做到这一点.
I also want to know is there any library(C, C++, PHP, Python) can help me to do such thing. Or how can I do this by myself.
还是第三个解决方案?
推荐答案
IMAP IDLE的优点是减少了开销,并(可能)提高了响应速度.
The advantage of IMAP IDLE is reduced overhead and (probably) increased responsiveness.
轮询的优点是所有服务器固有地支持轮询,而并非所有服务器都支持IDLE.
The advantage of polling is that it's inherently supported by all servers, whereas IDLE isn't supported by all servers.
对于库,@ Max指出Python中的imaplib和imaplib2.我确定您提到的其他语言也有类似的库.
As for libraries, @Max points out imaplib and imaplib2 in Python. I'm sure the other languages you mention have similar libraries.
关于第三个选项,您可以考虑使用 context.io 代替IMAP库.
As for third option, instead of IMAP libraries, you might look into using context.io.
这篇关于当我有很多帐户时,如何查询IMAP服务器中的新邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!