使用 Indy 检查未读消息
我只是为了好玩而在 Delphi 中做一个未读消息检查器应用程序。我正在使用 Indy 10。我可以连接 Gmail 并检索所有邮件,但我在这里遇到一个问题:我无法判断邮件是否已读。 TidMessage 组件中有一个 flag 属性,可以告诉我消息是否已被读取。 代码如下所示:
procedure TForm1.btTestConnectionClick(Sender: TObject);
var
i: Integer;
count: Integer;
flag: TIdMessageFlags;
begin
if (pop3Test.Connected) then begin
pop3Test.Disconnect;
end;
pop3Test.Username := edAccount.Text;
pop3Test.Password := edPassword.Text;
pop3Test.Host := HOST;
pop3Test.AuthType := patUserPass;
pop3Test.Port := PORT;
pop3Test.Connect;
Count := 0;
for i := pop3Test.CheckMessages downto 1 do begin
pop3Test.Retrieve(i, IdMessage1);
if (mfSeen in IdMessage1.Flags) then begin
Count := Count + 1;
end;
end;
ShowMessage(IntToStr(Count));
pop3Test.Disconnect;
end;
在测试邮箱中,有一封未读邮件,但所有检索到的邮件的 flags 枚举属性均为空,因此结果始终为 0。我是否做错了什么?是 Indy/Gmail 兼容性问题吗?
谢谢。
编辑:我肯定做错了什么,因为使用 Hotmail 帐户进行测试显示了相同的空标志属性问题。
I'm doing just for fun an unread messages checker application in Delphi. I'm using Indy 10. I can connect with Gmail and can retrieve all the messages but I'm facing a problem here: I cannot tell if a message is already read or not. There is a flag property in the TidMessage component that should tell me if the message has been read.
The code looks like this:
procedure TForm1.btTestConnectionClick(Sender: TObject);
var
i: Integer;
count: Integer;
flag: TIdMessageFlags;
begin
if (pop3Test.Connected) then begin
pop3Test.Disconnect;
end;
pop3Test.Username := edAccount.Text;
pop3Test.Password := edPassword.Text;
pop3Test.Host := HOST;
pop3Test.AuthType := patUserPass;
pop3Test.Port := PORT;
pop3Test.Connect;
Count := 0;
for i := pop3Test.CheckMessages downto 1 do begin
pop3Test.Retrieve(i, IdMessage1);
if (mfSeen in IdMessage1.Flags) then begin
Count := Count + 1;
end;
end;
ShowMessage(IntToStr(Count));
pop3Test.Disconnect;
end;
In the test mailbox there is one unread message but all the retrieved messages have the flags enum property empty so the result is always 0. Am I doing something wrong? Is it a problem of Indy/Gmail compatibility?
Thanks.
EDIT: I'm definitely doing something wrong as testing with a Hotmail account shows the same empty-flags property problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
POP3
协议不支持消息状态信息
服务器喜欢读取、回复或删除。尝试改用IMAP for Gmail
。the
POP3
protocol does not supportMessage state information
on the server like read, replied to, or deleted . try usingIMAP for Gmail
instead.找到这个答案的最好(也是最快)的方法是在 Indy 源代码中搜索“mfSeen”,您应该会发现它仅在 idIMAP* 单元中使用。 RRUZ 是正确的 - POP3 不提供这种固有的能力。在 POP3 中,您需要在客户端跟踪这一点。此标志添加到 IdMessage 是为了 IMAP 目的,而不一定是为了 POP3。
TIdMessageFlags 可能应该被命名为 TIdIMAPMessageFlags
The best (and quickest) way to find this answer would be to search the Indy sourcecode for "mfSeen" You should find it only utilized in idIMAP* units. RRUZ is correct - POP3 doesn't offer this inherent ability. In POP3 you need to track this on the client side. This flag was added to IdMessage for IMAP purposes, and not necessarily for POP3.
TIdMessageFlags should likely have been named TIdIMAPMessageFlags