简体   繁体   English

POP3:从POP3服务器接收邮件的最佳方法

[英]POP3: Best way the receive mail from POP3 server

What is the best way to receive messages from a POP3 Server? 从POP3服务器接收消息的最佳方法是什么? We have to build the POP3 Receiver client only and not the server. 我们只需要构建POP3接收器客户端,而不是服务器。 So we don't know the behavior of the server(eg: when the server deletes the messages etc). 因此,我们不知道服务器的行为(例如:当服务器删除消息时等)。

I know of the following options, but I am not able to present the case with proper reason. 我知道以下选项,但是我无法以适当的理由提出此案。 Please help. 请帮忙。

1. UUIDs . 1. UUID Are there any performance impacts of this if we save all the UUIDs? 如果保存所有UUID,这会对性能产生影响吗?

  1. With Flag.deleted , we delete the messages from the server. 使用Flag.deleted ,我们从服务器删除消息。 So everytime we poll the server we will get the latest message only. 因此,每次我们轮询服务器时,我们只会收到最新消息。 But some POP3 servers save the mails, so wont it be wrong if we delete the mails from server? 但是某些POP3服务器会保存邮件,因此,如果我们从服务器中删除邮件,这不会错吗?

  2. I save mails in the db. 我将邮件保存在数据库中。 So, I have a count of all received messages. 因此,我统计了所有收到的消息。 This is what is implemented. 这是实现的。 Take a count of received mails from the db (x). 计算从数据库 (x) 收到的邮件数 Take the latest count of mail from the pop3 folder (y). 从pop3文件夹中获取最新邮件数 (y)。 Then retrieve the mail from (y-x+1) to y. 然后从(y-x + 1)到y检索邮件。 This is what we have implemented. 这就是我们已经实现的。

  3. Get the list of headers from the folder. 从文件夹中获取标题列表 Get the list of headers after a particular date, and compare it with the list of UUIDs for say a last few couple of days. 获取特定日期之后的标头列表,并将其与UUID列表进行比较,例如最近几天。 Get the data for the remaining UUIDs from the folder. 从文件夹中获取剩余UUID的数据。 I think this is the best. 我认为这是最好的。 But will there be performance issues because of this? 但是会不会有性能问题吗?

Any help would be appreciated. 任何帮助,将不胜感激。 Thank you! 谢谢!

Note: I am using javamail! 注意:我正在使用javamail!

There's a lot of "diversity" in POP3 servers, so you may have to use different strategies with different servers. POP3服务器中存在很多“多样性”,因此您可能必须对不同的服务器使用不同的策略。

It sounds like you just want to use the POP3 server as a "mail drop", extracting all the messages from the server and saving them elsewhere. 听起来您只是想将POP3服务器用作“邮件投递”,从服务器中提取所有消息并将它们保存在其他位置。 This usually works pretty well if you're sure your program is the only one removing messages from the POP3 folder. 如果您确定程序是从POP3文件夹中删除邮件的唯一程序,则此方法通常效果很好。 Copy the message out of the folder, mark them deleted, and close the folder. 将消息复制出文件夹,将其标记为已删除,然后关闭文件夹。 The biggest complication is handling failure. 最大的麻烦是处理失败。 You might want to keep track of the UUIDs of the messages in the folder until you're sure they've been deleted from the folder so you know which ones you've already copied. 您可能要跟踪文件夹中邮件的UUID,直到确定已从文件夹中删除了邮件的UUID,以便知道已经复制了哪些邮件。 If your program or the server fails before you copy and delete all the messages, you can pick up where you left off. 如果在复制和删除所有消息之前您的程序或服务器出现故障,则可以从上次中断的地方继续。

If other programs are reading messages from the same POP3 folder, this all becomes more complicated. 如果其他程序正在从同一POP3文件夹中读取邮件,则所有操作都将变得更加复杂。

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

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