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.
IDLEcommand - server notifies the client when new mail is received). POP3 seems like the wrong tool for this kind of job. - Piskvor left the building