让多个 Java pop3 客户端与 GMail 一起使用

发布于 2024-07-29 08:36:54 字数 281 浏览 7 评论 0原文

我用 Java 编写了一个很好的程序,它连接到 gmail 帐户并下载发送给它的附件。 下载附件后,它会被标记为已读,并且不会再次下载。 该程序必须在多个实例中运行,每个程序都下载唯一的附件,这样单个附件就不会被下载两次。 问题是,目前如果附件大小合适,一个程序仍在下载它,而另一个实例连接并在附件被标记为已读之前也开始下载附件。

我尝试过检查和设置各种标志并检查文件夹是否打开,但似乎没有任何效果。 有什么解决办法吗?

更新:感谢您的快速解答,遗憾的是由于其他原因,IMAP 不是一个选项。

I have written a nice program in Java that connects to a gmail account and download atachments sent to it. Once an attachment has been downloaded, it is marked as read and is not downloaded ever again. This program will have to run in multiple instances with each program downloading unique attachments so that a single attachment is never downloaded twice. The problem is that at the moment if the attachment is of a decent size, one program is still downloading it, when another instance connects and also starts to download the attachment before it has been marked as read.

I have tried checking and setting various flags and checking whether the folder is open, nothing seems to work. Any solutions?

Update: Thank you for the quick answers, sadly IMAP is not an option due to other reasons.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

安人多梦 2024-08-05 08:36:54

考虑使用 IMAP - 它是为客户端-服务器交互而设计的。

Consider using IMAP instead - it is designed for client-server interaction.

深海少女心 2024-08-05 08:36:54

来自 RFC1939(邮局协议 - 版本 3):

POP3 并不旨在提供
广泛的操纵操作
服务器上的邮件; 通常,邮件是
下载然后删除。 RFC1730 中讨论了更高级(且复杂)的协议 IMAP4。 p>

From RFC1939 (Post Office Protocol - Version 3):

POP3 is not intended to provide
extensive manipulation operations of
mail on the server; normally, mail is
downloaded and then deleted. A more advanced (and complex) protocol, IMAP4, is discussed in RFC1730.

巷子口的你 2024-08-05 08:36:54

我不认为 POP3 是为多个同时访问而设计的。

问问自己:我真的需要多个进程访问同一个邮箱吗?

如果这样做,您将必须找到一种方法让这些进程相互通信。
使用通用数据库或服务器进程来协调操作。

IMAP 确实有更多选项,但我不确定您是否可以“锁定”单个邮件以将其标记为正在处理。

I don't think POP3 is made for multiple simultaneous access.

Ask yourself this: do i really need multiple processes accessing the same mailbox?

If you do, you'll have to find a way to have these processes communicate to each other.
Use a common database or server process to coordinate actions.

IMAP does have more options, but i'm not sure if you can "lock" a single mail to mark it as being processed.

殊姿 2024-08-05 08:36:54

正如其他人所提到的,POP3 并不是真正适合这种情况。

如果您绝对必须使用 POP3,我建议将所有电子邮件下载到中间服务器,该服务器对邮件进行排序并使它们可供其他每个客户端使用。

听起来您只是想分散电子邮件的处理。 如果是这种情况,您只需让每个客户端连接到中间服务器即可检索下一条可用消息。

我不确定您的限制是什么,但您甚至可能想考虑通过电子邮件以外的其他方式接收附件。 如果人们上传文件,您可以设置一个 Web 表单,自动将每个文件发送到应用程序的下一个可用实例进行处理。

As the others have mentioned, POP3 isn't really intended for this kind of scenario.

If you absolutely have to use POP3, I'd suggest downloading all the e-mail to an intermediate server which sorts the messages and makes them available for each of the other clients.

It sounds like you're just trying to distribute the processing of the e-mails. If that's the case, you can just have each client connect to your intermediate server to retrieve the next available message.

I'm not sure what your constraints are, but you may even want to consider receiving the attachments some other way besides e-mail. If people are uploading files, you could set up a web form that automatically sends each file to the next available instance of your application for processing.

め可乐爱微笑 2024-08-05 08:36:54

如果您需要保持 POP3 连接,您可以保留先前下载的消息 ID 的本地数据库。 然后新实例可以在再次下载之前进行检查。 不过,最好的解决方案是使用 IMAP,因为 IMAP 能够在下载之前设置已读/未读标志。

If you need to stay with a POP3 connection, you could keep a local database of previously downloaded message ids. Then new instances could check against that before downloading again. The best solution is just to use IMAP, though, as IMAP is able to set the read/unread flags before downloading.

孤单情人 2024-08-05 08:36:54

您可以在开始下载之前将邮件标记为已读,然后开始下载。

You could mark the mail as read before starting the download, and then start downloading it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文