Indy POP3 定期接收电子邮件
我正在尝试用delphi构建一个应用程序,它必须每30秒检查一次gmail收件箱,并且必须处理特殊目的的电子邮件。
使用 Indy POP3 组件构建了该应用程序,部分代码如下。
If Not POP3.Connected Then
Begin
POP3.Host := 'pop.gmail.com';
POP3.Port := 995;
POP3.Username := 'email';
POP3.Password := 'password';
SSL.Host := POP3.Host;
SSL.Port := POP3.Port;
SSL.Destination := SSL.Host + ':' + IntToStr(SSL.Port);
POP3.IOHandler := SSL;
POP3.UseTLS := utUseImplicitTLS;
// try etc...
POP3.Connect;
End;
MsgCnt := POP3.CheckMessages;
For i := 1 To MsgCnt Do
Begin
POP3.Retrieve(i, Msg);
// process message.. etc..
End;
我有一个问题,我将在下面尝试解释;
- 如果我每 30 秒断开并连接 POP3,经过一些尝试 服务器拒绝我的连接,我收到“套接字错误”。如果我尝试不 每 30 秒连接一次 只需每 30 秒检索一次电子邮件 我 我没有收到新电子邮件。
- 而且,如果我没有断开连接或使用“DisconnectNotifyPeer”命令,我会一次又一次地收到阅读电子邮件,但如果我可以解决上述问题,我会处理这个问题,但有关此问题的任何其他建议也会对我有帮助
。您认为 ?我能做些什么来解决这个问题,不是每 30 秒连接一次,而是接收新电子邮件?是否有任何命令或函数的作用类似于 ADO Requery 方法或其他方法?
顺便说一句,我已经尝试过使用其他一些 godaddy 邮件帐户,它在工作 3 或 4 次后也拒绝了我的连接,我想用 gmail (google apps) 解决这个问题。
感谢您的帮助。
I am trying to build an application with delphi, which has to check gmail inbox every 30 seconds, and has to process emails for special purpose.
Have build that application using Indy POP3 component, part of code is below.
If Not POP3.Connected Then
Begin
POP3.Host := 'pop.gmail.com';
POP3.Port := 995;
POP3.Username := 'email';
POP3.Password := 'password';
SSL.Host := POP3.Host;
SSL.Port := POP3.Port;
SSL.Destination := SSL.Host + ':' + IntToStr(SSL.Port);
POP3.IOHandler := SSL;
POP3.UseTLS := utUseImplicitTLS;
// try etc...
POP3.Connect;
End;
MsgCnt := POP3.CheckMessages;
For i := 1 To MsgCnt Do
Begin
POP3.Retrieve(i, Msg);
// process message.. etc..
End;
I have a problem with that which I'll try to explain below ;
- If I disconnect and connect POP3 every 30 seconds, after some tries
server refuses my connection and I got "socket error". If I try not
to connect every 30 seconds just retrieve emails every 30 seconds I
am not getting new emails. - And, I recieve read emails again and again if I am not disconnected or used "DisconnectNotifyPeer" command, but I'll handle this if I can solve my problem above, but any other suggestions about this issue will help me too..
What do you think ? what can I do to fix this issue, not connecting every 30 seconds but receiving new emails ? Is there any commands or functions which will act like ADO Requery method or something else ?
And by the way, I've tried it with some other godaddy mail account it also refused my connection after it worked for 3 or 4 times, I want to solve this issue with gmail (google apps) .
Thanks For your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有显示所有代码,但我假设您将 POP3 控件保持连接到服务器...最终服务器会超时并断开连接。
只要正确断开连接,您应该能够每 30-60 秒通过 POP3 连接一次。但是,如果您想保持连接并立即更新新邮件,那么这就是 IMAP 功能,而不是 POP3。
You aren't showing all of your code, but I am assuming that you are leaving the POP3 control connected to the server... eventually the server times you out and disconnects you.
You should be able to connect every 30-60 seconds via POP3 as long as you are disconnecting properly. But, if you want to stay connected and update new mail immediately, then that's IMAP functionality, not POP3.
30秒太频繁了。使用更长的间隔,至少几分钟。
至于连接到 POP3 服务器时无法接收新电子邮件,邮箱在您登录时会被锁定,并保持锁定状态,直到您断开连接为止。您只能查看和操作登录时出现的消息。这是 POP3 设计的核心。它不适用于通用文件夹/消息管理。这就是 IMAP 的专用用途(正如您已经发现的那样)。 POP3 仅用于下载和删除邮件,因此只需下载/删除邮件,断开连接,然后稍等片刻即可再次执行此操作。
30 seconds is too often. Use a longer interval, say a few minutes at least.
As for not receiving new emails while connected to a POP3 server, the mailbox becomes locked when you login and remains locked until you disconnect. You can see and manipulate only the messages that are present at the time of login. That is at the core of POP3's design. It is not meant for generalized folder/message management. That is what IMAP is specifically for (as you already discovered). POP3 is only meant for downloading and deleting messages, so just download/delete the messages, disconnect, and wait awhile to do it again.