Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indy POP3 periodically receiving e-mails

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.

like image 840
Adnan M. TÜRKEN Avatar asked Nov 27 '25 15:11

Adnan M. TÜRKEN


2 Answers

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.

like image 180
Darian Miller Avatar answered Nov 30 '25 17:11

Darian Miller


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.

like image 38
Remy Lebeau Avatar answered Nov 30 '25 17:11

Remy Lebeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!