Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Verbindung serverseitig geschlossen - Abhilfe? (https://www.delphipraxis.net/20659-verbindung-serverseitig-geschlossen-abhilfe.html)

fxbasic 21. Apr 2004 07:55


Verbindung serverseitig geschlossen - Abhilfe?
 
Guten Morgen,

ich bin grad mit einem Prog beschäftigt, dass bei verschiedenen eMail-Accounts nach eMails schaut. Die Profildaten sind in einer Ini-Datei gespeichert. Code sieht aus wie folgt:

Delphi-Quellcode:
function GetMails(host,userid,passw: string): integer;
begin
with form1 do begin
pop.Host := host;
pop.UserId := userid;
pop.Password := passw;
mkstatus('Verbinde...');
pop.Connect;
try result := pop.CheckMessages except begin
result := -1;
pop.disconnect;
end;
end;
mkstatus('Trenne...');
pop.Disconnect;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var ini: TIniFile;
var i,x: integer;
var t1,t2: TTreeNode;
begin
TreeMake;
ini := TIniFile.create(extractfilepath(application.exename)+'settings.ini');
treeview1.Items.Clear;
t1 := treeview1.Items.AddChild(nil,'Konten');
for i := 0 to ini.ReadInteger('General','Profiles',0)-1 do begin
label2.caption := ini.readstring('Profil'+inttostr(i+1),'Name','');
application.processmessages;
x := GetMails(ini.readstring('Profil'+inttostr(i+1),'Host',''),
         ini.readstring('Profil'+inttostr(i+1),'UserID',''),
         ini.readstring('Profil'+inttostr(i+1),'Password',''));
t2 := treeview1.Items.AddChild(t1,ini.readstring('Profil'+inttostr(i+1),'Name','')+' ('+inttostr(x)+' eMails)');
end;
// ...
label2.caption := 'Fertig.';
label4.caption := 'Fertig.';
end;
Das funktioniert mit GMX- und "echten" (also kein Webmailer) eMail-Konten auch wunderbar. Bei freemail.web.de allerdings ist nur ein POP-Login pro 15 Min erlaubt. Frage ich mit meinem Prog jetzt mehr als einmal pro 15 Min ab, so verbindet er auch brav nur klebt mir dann die WEB.de Meldung von wegen 15 Min um die Ohren und beendet selbstständig die Verbindung. Folge: Der Rest des Codes wird nicht mehr abgearbeitet.

Und nun die Frage: wie kann man auf solche Situationen programmiertechnisch reagieren, da diese Meldung auch nicht über IDPOP3.onStatus abzufangen ist?

Mit bestem Dank im Voraus, fxbasic

shmia 21. Apr 2004 10:38

Re: Verbindung serverseitig geschlossen - Abhilfe?
 
Hmm, dein Programmcode gefällt mir nicht so richtig (Formatierung und Inhalt).
Besser so:
Delphi-Quellcode:
function GetMails(const host,userid,passw: string): integer;
begin
   // richtig einrücken, sonst siehts sch.... aus
   with form1 do
   begin
      pop.Host := host;
      pop.UserId := userid;
      pop.Password := passw;
      mkstatus('Verbinde...');
      pop.Connect;
      if not pop.Connected then // prüfe, ob Host mich abgelehnt hat
         raise Exception.CreateFmt('Connection terminated by host %s', [host]);
      try // Resource-Schutzblock
         result := pop.CheckMessages;
      finally
         mkstatus('Trenne...');
         pop.Disconnect;
      end;
   end;
end;
Und später dann:
Delphi-Quellcode:
try
   x := GetMails(ini.readstring('Profil'+inttostr(i+1),'Host',''),
         ini.readstring('Profil'+inttostr(i+1),'UserID',''),
         ini.readstring('Profil'+inttostr(i+1),'Password',''));
   t2 := treeview1.Items.AddChild(t1,ini.readstring('Profil'+inttostr(i+1),'Name','')+' ('+inttostr(x)+' eMails)');
except
   on E:Exception do
      t2 := treeview1.Items.AddChild(t1,ini.readstring('Profil'+inttostr(i+1),'Name','')+E.Message);
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:30 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz