我引用Idpop3控件,连接多个服务器去接收邮件,在实现中,使用了循环,但是当一个服务器出现异常(就比如说,连接失败吧),该次循环之后的都不执行了,为什么呀???
说明:当有3个服务器时,接收第一个服务器的时候,连接失败,Idpop3提示连接失败的错误,但是就是继续执行了,因为我的循环中还要接收第二个和第三个服务器的邮件呢,并且,我对这个异常没处理。代码如下:
Listtmp: TStringList;
......
for EmailAddCount:=1 to 3 do
begin
CutString(ListTmp,DelEmailList[EmailAddCount-1]);
if Idpop31.Connected then
begin
Idpop31.Disconnect;
end;
Idpop31.Host:=ListTmp[1];
Idpop31.Port:=110;
Idpop31.Username:=ListTmp[2];
Idpop31.Password:=ListTmp[3]; try
begin
Idpop31.Connect(1000);
end
finally
begin
StatusBar1.SimpleText:='连接服务器失败!';
end
end;
end
说明:当有3个服务器时,接收第一个服务器的时候,连接失败,Idpop3提示连接失败的错误,但是就是继续执行了,因为我的循环中还要接收第二个和第三个服务器的邮件呢,并且,我对这个异常没处理。代码如下:
Listtmp: TStringList;
......
for EmailAddCount:=1 to 3 do
begin
CutString(ListTmp,DelEmailList[EmailAddCount-1]);
if Idpop31.Connected then
begin
Idpop31.Disconnect;
end;
Idpop31.Host:=ListTmp[1];
Idpop31.Port:=110;
Idpop31.Username:=ListTmp[2];
Idpop31.Password:=ListTmp[3]; try
begin
Idpop31.Connect(1000);
end
finally
begin
StatusBar1.SimpleText:='连接服务器失败!';
end
end;
end
begin
Idpop31.Connect(1000);
end
except
on E :Exception do
begin
StatusBar1.SimpleText:=ListTmp[1]+'连接服务器失败!'+E.message;
continue;
end
end;
这样应该就可以