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 ;
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.
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.
connect
checkmessages
save messages
disconnect
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 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With