为什么我写的EMAIL程序总不成功?(100分)(100分)

  • 主题发起人 主题发起人 agezhu
  • 开始时间 开始时间
A

agezhu

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils,Controls, Forms, Dialogs,winsock,
StdCtrls, Classes;
const
BaseTable:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
crlf=#13#10;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1:TForm1;
sbuf:array[0..1024] of char;
wsadata:twsadata;
fsocket,fport,step:integer;
sockaddrin:tsockaddrin;
fhost,s1:string;
implementation

{$R *.DFM}

function EncodeBase64(Source:string):string;//Base64转换函数
var
Times,LenSrc,i:integer;
x1,x2,x3,x4:char;
xt:byte;
begin
result:='';
LenSrc:=length(Source);

if LenSrc mod 3 =0 then
Times:=LenSrc div 3
else
Times:=LenSrc div 3 + 1;

for i:=0 to times-1 do
begin

if LenSrc >= (3+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(Ord(Source[2+i*3]) shl 2) and 60;
xt:=xt or (ord(Source[3+i*3]) shr 6);
x3:=BaseTable[xt+1];
xt:=(ord(Source[3+i*3]) and 63);
x4:=BaseTable[xt+1];
end
else
if LenSrc>=(2+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(ord(Source[2+i*3]) shl 2) and 60;
x3:=BaseTable[xt+1];
x4:='=';
end
else
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
x2:=BaseTable[xt+1];
x3:='=';
x4:='=';
end;
result:=result+x1+x2+x3+x4;
end;
end;

function temail(n:string;p:string):integer;//发送邮件函数
var
s2,i:string;
sbuf1:array[0..512] of char;
x,t:integer;
begin
x:=1;
t:=0;

s1:='EHLO smtp.hacker.com'+crlf;
strcopy(sbuf,pchar(s1));
send(fsocket,sbuf,strlen(sbuf),msg_dontroute);

repeat
recv(fsocket,sbuf1,400,0);
s2:=string(sbuf1);

s2:=copy(s2,0,3);

if (s2='250')or(s2='220')or(s2='334')or(S2='235') then
begin
case x of
1:s1:='AUTH LOGIN'+crlf;
4:s1:='mail from:<getoicq@sohu.com>'+crlf;
5:s1:='rcpt to:<agezhu@sohu.com>'+crlf;
6:s1:='data'+crlf;
8:s1:='quit'+crlf;
end;
end;

if s2='334' then
begin
case x of
2:s1:=n+crlf;
3:s1:=p+crlf;
end;
end;

if s2='354' then
begin
s1:='from:<getoicq@21cn.com>'+crlf
+'to:<agezhu@sohu.com>'+crlf
+'subject:qq2001'+crlf
+'test is good'+crlf
+crlf
+'.'+crlf;
end;

if (s2<>'250')and(s2<>'220')and(s2<>'334')and(s2<>'345')and(s2='334')and(S2='235') then break;

strcopy(sbuf,pchar(s1));
send(fsocket,sbuf,strlen(sbuf),msg_dontroute);
t:=t+1;
inc(x);
sleep(150);
until (x>7)or (t>15)

end;



procedure TForm1.Button1Click(Sender: TObject);//初始化
var
err,y:integer;
n,p:string;
begin

err:=wsastartup($0101,wsadata);
fsocket:=socket(pf_inet,sock_stream,ipproto_ip);
fhost:=edit3.Text;
fport:=25;
sockaddrin.sin_addr.s_addr:=inet_addr(pchar(fhost));
sockaddrin.sin_family := pf_inet;
sockaddrin.sin_port :=htons(fport);
err:=connect(fsocket,sockaddrin, sizeof(sockaddrin));
n:=edit1.text;
p:=edit2.text;
n:=EncodeBase64(n);
p:=EncodeBase64(p);
temail(n,p);

err:=closesocket(fsocket);
err:=wsacleanup;
end;
end.

服务器返回的信息
220 smtp03.sohu.com ESMTP
|Na>喡﹪l羴d

250-smtp03.sohu.com
250-PIPELINING
250-SIZE 2097152
250-ETRN
250-AUTH LOGIN
250-AUTH=LOGIN
250 8BITMIME


334 VXNlcm5hbWU6
m
250-PIPELINING
250-SIZE 2097152
250-ETRN
250-AUTH LOGIN
250-AUTH=LOGIN
250 8BITMIME


501 Error: malformed authentication response
502 Error: command not implemented
50-AUTH=LOGIN
250 8BITMIME


501 Error: malformed authentication response
502 Error: command not implemented
50-AUTH=LOGIN
250 8BITMIME


501 Error: malformed authentication response
502 Error: command not implemented
50-AUTH=LOGIN
250 8BITMIME


501 Error: malformed authentication response
502 Error: command not implemented
50-AUTH=LOGIN
250 8BITMIME



 
后退
顶部