Delphi 和 Indy 10 无法读取第二个 gmail 电子邮件。阅读一次后的时间

Delphi and Indy 10 unable to read gmail emails 2nd. time after reading once

我尝试从一个 gmail 帐户获取电子邮件数量,第一次它工作正常,之后每次,只要我不断开与服务器的连接(我在它之前通过调试器停止执行断开连接命令)。 但是当我执行断开连接后,我就再也找不回邮件了,邮件数量一直是0。但是在线查看时邮件还在收件箱里,我可以在线打开邮件阅读内容,bit无法找回Indy 不再发送电子邮件。

这只发生在 gmail 上,我试过的其他电子邮件帐户不会发生。

下面是部分代码。 pop.CheckMessages returns 1 第一次,但一旦我断开并重新开始,它总是 returns 0.

有人知道我做错了什么吗?就像邮件被标记了一样,无法通过电子邮件客户端再次阅读。

pop:=tidpop3.Create(nil);
pop.Host := 'pop.gmail.com';
pop.Port := 995;
pop.Username := MyUserName;
pop.Password := MyPassword;
pop.ConnectTimeout := 10000;
ssl := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
ssl.SSLOptions.Method := sslvTLSv1;
ssl.SSLOptions.Mode := sslmClient;
pop.IOHandler := ssl;
pop.UseTLS := utUseImplicitTLS;
pop.Connect;
num:=pop.CheckMessages;
pop.Disconnect;
pop.Free;
ssl.Free;

POP 从服务器上删除邮件 - 你只读一次(至少在大多数实现中 - GMail separates POP and IMAP functionality 这有点令人困惑,为什么你仍然在线看到邮件。从 POP 的角度来看,邮件是从服务器上消失了,但 Google 仍然保留在那里,标记为 POP 失效,以免破坏 IMAP 功能)。如果您想将邮件留在服务器上并与服务器邮件状态保持同步,请使用 IMAP。

在传统的 POP 会话中,您必须明确告诉服务器您希望在读取服务器副本后将其删除 - 客户端通常配置为自动执行此操作,因为这是使用 POP 的常见方式。使用 TIdPOP3 您必须显式调用 IdPOP3.Delete(),但 GMail 的 POP 实现 is somewhat different.

How does normal mode work?

A POP client session starts with your mail client (Thunderbird, Outlook, Sparrow, etc.) asking your Gmail mailbox for a list of messages that haven't yet been downloaded. After Gmail provides the list of messages to your mail client, your client will begin downloading them. In POP normal mode, Gmail provides a list of about 250 of the oldest messages that have not yet been downloaded (Spam and Trash are excluded). Once a message is downloaded, Gmail marks it as 'popped'.

因此,在“正常”模式下,GMail 只会通过 POP 发送一次邮件。要访问仍在服务器上但已经 'popped' 的邮件,您可以选择使用最近模式的 GMail(请参阅上面的 link)。

What happens to my messages in Gmail after they've been popped?

When using recent mode, 'popped' messages (downloaded in normal mode) will still be shown to mail clients. This means that even if one POP client (that uses normal mode) marks a message as popped, another POP client (that uses recent mode) will still be able to see the message (unless you've set Gmail to delete messages that have been downloaded via POP in the When messages are accessed with POP option, in which case the message will be sent to Trash after it's been downloaded by the POP client in normal mode).

Unlike in normal mode, you must set your POP client to leave messages on the server (and not delete them), because when a POP client issues a DELE (delete) command in recent mode, it is sent to Trash in Gmail, regardless of the user's When messages are accessed with POP setting. If one of the POP clients deletes messages, they won't be visible to the other POP clients ever again (unless moved out of Trash).

Remy 的回答提供了有关 使用 POP 设置访问邮件时的更多详细信息。

POP 是上个世纪的古老恐龙。它是在服务器 space 昂贵、互联网速度极慢且人们通常只有一台计算机的情况下设计的。从字面上看,使用 POP 就像将服务器用作邮箱一样。您将检查邮件并将所有邮件下载到本地客户端,然后从服务器中删除它们(清空邮箱)。这在服务器上节省了 space 并使检查新邮件的速度更快,但这意味着您的所有邮件最终都存储在您用来检查邮件的任何计算机上,这是 唯一 的地方它存在。时代变了——POP 通常应该被认为已经死了。只是不要使用它。

在 Gmail 的设置中,有一个部分用于配置在通过 POP 访问时如何处理电子邮件:

"When messages are accessed with POP" 设置有 4 个选项:

听起来您启用了 "delete Gmail's copy" 选项。

这仅适用于 Gmail。大多数电子邮件提供商不会像这样分离他们的 POP 和 IMAP 实现。他们通常只访问一个收件箱,并使两种协议保持同步。