有关nmpop3控件的使用(100分)

  • 主题发起人 主题发起人 startlxuwei
  • 开始时间 开始时间
S

startlxuwei

Unregistered / Unconfirmed
GUEST, unregistred user!
使用nmpop3收发邮件时,老是显示connection failed,这是为什么?
 
贴代码出来吧,就说连接失败原因很多啊,服务器地址不对,用户名密码不对都有可能
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask;

type
TForm1 = class(TForm)
Label1: TLabel;
useredit: TEdit;
Label2: TLabel;
Label3: TLabel;
pop3edit: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
passwordedit: TMaskEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
uses unit2,unit3;
{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
useredit.Text:='startlxuwei';
pop3edit.Text:='pop3.elong.com';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if (useredit.Text<>'') and (passwordedit.Text<>'') and (pop3edit.Text<>'') then
begin
form2:=tform2.create(nil);
form2.show;
end
else
showmessage('please complete all of the fillings');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
useredit.Text:='';
passwordedit.Text:='';
pop3edit.Text:='';
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;

end.
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Psock, NMpop3, StdCtrls, ComCtrls;

type
TForm2 = class(TForm)
ListBox1: TListBox;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
NMPOP31: TNMPOP3;
StatusBar1: TStatusBar;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure NMPOP31List(Msg, Size: Integer);
procedure NMPOP31ConnectionFailed(Sender: TObject);
procedure NMPOP31InvalidHost(var Handled: Boolean);
procedure NMPOP31ConnectionRequired(var Handled: Boolean);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure NMPOP31Connect(Sender: TObject);
procedure NMPOP31RetrieveStart(Sender: TObject);
procedure NMPOP31Success(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation
uses unit1,unit3;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
with nmpop31 do
begin
attachfilepath:='.';
deleteonread:=false;
timeout:=2000;
host:=form1.pop3edit.text;
userid:=form1.useredit.text;
password:=form1.passwordedit.text;
connect;

end;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
nmpop31.disconnect;
end;

procedure TForm2.NMPOP31List(Msg, Size: Integer);
begin
listbox1.items.add(inttostr(msg));
end;

procedure TForm2.NMPOP31ConnectionFailed(Sender: TObject);
begin
showmessage('connection failed');
end;

procedure TForm2.NMPOP31InvalidHost(var Handled: Boolean);
var
tmpstr:string;
begin
if inputquery('invaild host!','specify a new host:',tmpstr) then
begin
nmpop31.host:=tmpstr;
handled:=true;

end;

end;

procedure TForm2.NMPOP31ConnectionRequired(var Handled: Boolean);
begin
if messagedlg('connection required correct?',mtconfirmation,mbokcancel,0)=mrok then
begin
handled:=true;
nmpop31.connect;
end;
end;

procedure TForm2.Button4Click(Sender: TObject);
begin
close;

end;

procedure TForm2.Button3Click(Sender: TObject);
begin
nmpop31.getmailmessage(strtoint(listbox1.items[listbox1.itemindex]));
form3:=tform3.create(nil);
form3.show;
end;

procedure TForm2.NMPOP31Connect(Sender: TObject);
begin
with nmpop31 do
begin
getmailmessage(mailcount);
list;
label1.caption:='共有'+inttostr(mailcount)+'封邮件';
disconnect;
end;
end;
procedure TForm2.NMPOP31RetrieveStart(Sender: TObject);
begin
statusbar1.SimpleText:='connect starting';
end;

procedure TForm2.NMPOP31Success(Sender: TObject);
begin
statusbar1.SimpleText:='connecttion success';
end;

end.
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Psock, NMpop3, StdCtrls, ComCtrls;

type
TForm2 = class(TForm)
ListBox1: TListBox;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
NMPOP31: TNMPOP3;
StatusBar1: TStatusBar;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure NMPOP31List(Msg, Size: Integer);
procedure NMPOP31ConnectionFailed(Sender: TObject);
procedure NMPOP31InvalidHost(var Handled: Boolean);
procedure NMPOP31ConnectionRequired(var Handled: Boolean);
procedure Button4Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure NMPOP31Connect(Sender: TObject);
procedure NMPOP31RetrieveStart(Sender: TObject);
procedure NMPOP31Success(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation
uses unit1,unit3;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
with nmpop31 do
begin
attachfilepath:='.';
deleteonread:=false;
timeout:=2000;
host:=form1.pop3edit.text;
userid:=form1.useredit.text;
password:=form1.passwordedit.text;
connect;

end;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
nmpop31.disconnect;
end;

procedure TForm2.NMPOP31List(Msg, Size: Integer);
begin
listbox1.items.add(inttostr(msg));
end;

procedure TForm2.NMPOP31ConnectionFailed(Sender: TObject);
begin
showmessage('connection failed');
end;

procedure TForm2.NMPOP31InvalidHost(var Handled: Boolean);
var
tmpstr:string;
begin
if inputquery('invaild host!','specify a new host:',tmpstr) then
begin
nmpop31.host:=tmpstr;
handled:=true;

end;

end;

procedure TForm2.NMPOP31ConnectionRequired(var Handled: Boolean);
begin
if messagedlg('connection required correct?',mtconfirmation,mbokcancel,0)=mrok then
begin
handled:=true;
nmpop31.connect;
end;
end;

procedure TForm2.Button4Click(Sender: TObject);
begin
close;

end;

procedure TForm2.Button3Click(Sender: TObject);
begin
nmpop31.getmailmessage(strtoint(listbox1.items[listbox1.itemindex]));
form3:=tform3.create(nil);
form3.show;
end;

procedure TForm2.NMPOP31Connect(Sender: TObject);
begin
with nmpop31 do
begin
getmailmessage(mailcount);
list;
label1.caption:='共有'+inttostr(mailcount)+'封邮件';
disconnect;
end;
end;
procedure TForm2.NMPOP31RetrieveStart(Sender: TObject);
begin
statusbar1.SimpleText:='connect starting';
end;

procedure TForm2.NMPOP31Success(Sender: TObject);
begin
statusbar1.SimpleText:='connecttion success';
end;

end.
 
没看出那里有问题啊,看看服务器吧
 
pop SERVER ADDRESS ERROR?
 
没有啊,这个pop3.elong.com是从我的邮箱里搞下来的,所以应该不会有错的!
 
换用idpop3把(Indy控件)
 
host应该怎么写,例如elong的host是不是应该写成smtp.elong.com?
 
我也碰到这样的问题,今天有找了一天都没有发现是那里的错误,太郁闷了,会不会是与
服务器有关,还是网络设置有关,
 
后退
顶部