问:最小的邮件发送程序(<100K)怎么做?能否做出来?(100分)

  • 主题发起人 主题发起人 HN-Huang
  • 开始时间 开始时间
H

HN-Huang

Unregistered / Unconfirmed
GUEST, unregistred user!
问:最小的邮件发送程序(&lt;100K)怎么做?能否做出来?<br><br>我只要<br>uses nmsmtp;<br>程序就从44k变成330k了。<br><br>是不是不可能&lt;100K呢?<br>如果能,请告诉我,我该怎么做呢?
 
直接用API来写就可以了.<br>下面是某程序的部分片段,看懂后相信你的问题就OK了.<br>--------------------------------------------------<br>program XXXX;<br><br>uses<br>&nbsp; windows,messages,winsock,sysutils;<br><br>{$R *.RES}<br><br>const<br>&nbsp; CRLF=#13#10;<br>var<br>&nbsp; thd:array[1..1000] of integer;<br>&nbsp; tid:array[1..1000] of dword;<br>&nbsp; faint,hMutex,mcount,speed,newtime,oldtime,num,count,err:integer;<br>&nbsp; s1:string;<br>&nbsp; sbuf:array[0..1024] of char;<br>&nbsp; dest:string;<br>&nbsp; allstart:boolean;<br>//以下是网络连接的过程<br>function StartNet(host:string;port:integer):integer;<br>var<br>&nbsp; wsadata:twsadata;<br>&nbsp; fsocket:integer;<br>&nbsp; SockAddrIn:TSockAddrIn;<br>&nbsp; mct,err:integer;<br>begin<br>&nbsp; //为网络连接作好准备(用winsock1.1以上版本)<br>&nbsp; err:=WSAStartup($0101,WSAData);<br>&nbsp; //创建一个客户端套接字(Client Socket,用SOCK_STREAM,即TCP协义)<br>&nbsp; FSocket := socket(PF_INET, SOCK_STREAM,IPPROTO_IP);<br>&nbsp; //初始化网络数据<br>&nbsp; SockAddrIn.sin_addr.s_addr:=inet_addr(PChar(host));<br>&nbsp; SockAddrIn.sin_family := PF_INET;<br>&nbsp; SockAddrIn.sin_port :=htons(port);<br>&nbsp; //客户端向smtp进行连接<br>&nbsp; mct:=0;<br>&nbsp; repeat<br>&nbsp; err:=connect(FSocket,SockAddrIn, SizeOf(SockAddrIn));<br>&nbsp; inc(mct);<br>&nbsp; if mct&gt;0 then break;<br>&nbsp; until err=0;<br>&nbsp; Result:=FSocket;<br>end;<br>//以下是网络关闭的过程<br>procedure StopNet(Fsocket:integer);<br>var<br>&nbsp; err:integer;<br>begin<br>&nbsp; //发信结束,关闭客户端套接字(Close Client Socket)<br>&nbsp; err:=closesocket(FSocket);<br>&nbsp; //清除网络参数<br>&nbsp; err:=WSACleanup;<br>end;<br><br>function PostData(uid,pid:string):integer;<br>const<br>&nbsp; MaxSize=1024;<br>var<br>&nbsp; FSocket:integer;<br>&nbsp; HeadStr,PostStr:string;<br>&nbsp; DataBuf:array[0..MaxSize*60] of char;<br>&nbsp; TmpBuf:array[0..MaxSize*16] of char;<br>&nbsp; SubStr:array[0..MaxSize] of char;<br>&nbsp; err,cut:integer;<br>begin<br>// &nbsp;repeat<br>&nbsp; &nbsp; FSocket:=StartNet('202.104.32.236',80);<br>&nbsp; &nbsp; // &nbsp;PostData(FSocket,dest);<br>&nbsp; &nbsp; //--------------------申请第一步-------------------------------------<br>&nbsp; &nbsp; PostStr:=//下面是POST数据部分<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'FullName=&amp;NewUserName='+uid+'&amp;DomainName=21cn.com&amp;submit.x=33&amp;submit.y=10';<br>&nbsp; &nbsp; HeadStr:=//下面是HEAD数据部分<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'POST /extend/gb/std/NULL/NULL/register.gen HTTP/1.1'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Accept-Language: zh-cn'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Content-Type: application/x-www-form-urlencoded'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Accept-Encoding: gzip, deflate'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Host: webmail.21cn.com'+CRLF+ &nbsp; //webmail.21cn.com=202.104.32.236<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Connection: Keep-Alive'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Referer: http://webmail.21cn.com/extend/gb/UserName.htm'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Content-Length: '+inttostr(length(PostStr))+CRLF+CRLF;<br>&nbsp; &nbsp; strcopy(DataBuf,pchar(HeadStr+PostStr+CRLF));<br>&nbsp; &nbsp; err:=send(FSocket,DataBuf,strlen(DataBuf),MSG_DONTROUTE);<br>&nbsp; &nbsp; strcopy(DataBuf,pchar(''));<br>&nbsp; &nbsp; repeat<br>&nbsp; &nbsp; &nbsp; err:=recv(FSocket,TmpBuf,MaxSize,0);<br>&nbsp; &nbsp; &nbsp; strcopy(DataBuf,pchar(strpas(DataBuf)+strpas(TmpBuf)));<br>&nbsp; &nbsp; until err&lt;=0;<br>&nbsp; &nbsp; strcopy(SubStr,pchar('已经被占用了'));<br>&nbsp; &nbsp; if AnsiStrPos(DataBuf,SubStr)&lt;&gt;nil then<br>&nbsp; &nbsp; &nbsp; WriteCaption(hEditEMail,pchar('用户已存在'));<br>&nbsp; &nbsp; strcopy(SubStr,pchar('用户名太短'));<br>&nbsp; &nbsp; if AnsiStrPos(DataBuf,SubStr)&lt;&gt;nil then<br>&nbsp; &nbsp; &nbsp; WriteCaption(hEditEMail,pchar('用户名太短'));<br>&nbsp; &nbsp; strcopy(SubStr,pchar('非法字符'));<br>&nbsp; &nbsp; if AnsiStrPos(DataBuf,SubStr)&lt;&gt;nil then<br>&nbsp; &nbsp; &nbsp; WriteCaption(hEditEMail,pchar('非法字符'));<br><br>&nbsp; &nbsp; WriteCaption(handle,pchar(inttostr(strlen(DataBuf))));<br>&nbsp; &nbsp; StopNet(Fsocket);<br>// &nbsp; &nbsp;WriteCaption(hEditCount,pchar(inttostr(strlen(DataBuf))));<br><br>// &nbsp;until err&gt;0;<br>&nbsp; //------------------------------<br>&nbsp; FSocket:=StartNet('202.104.32.236',80);<br>&nbsp; //--------------------申请第二步-------------------------------------<br>&nbsp; PostStr:=//下面是POST数据部分<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Agree=Agree&amp;DomainName=21cn.com&amp;NewUserName='+uid+'&amp;Version=2&amp;'+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'LastName=xxx&amp;CommonName=xxx&amp;Password='+pid+'&amp;ConfirmPassword='+pid+'&amp;PasswordReminderQuestion=xxx&amp;PasswordReminderAnswer=xxx'+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'&amp;PersonalID=&amp;Gender=0&amp;birth_year=1999&amp;birth_month=1&amp;birth_day=1&amp;MailBox=&amp;PasswordReminderAnswer3=&amp;Country=Null&amp;Province=Null&amp;City=';<br>&nbsp; HeadStr:=//下面是HEAD数据部分<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'POST /extend/gb/std/NULL/NULL/AddUser1.gen HTTP/1.1'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Accept-Language: zh-cn'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Content-Type: application/x-www-form-urlencoded'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Accept-Encoding: gzip, deflate'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Host: webmail.21cn.com'+CRLF+ &nbsp; //webmail.21cn.com=202.104.32.236<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Connection: Keep-Alive'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Referer: http://webmail.21cn.com/extend/gb/std/NULL/NULL/register.gen?FullName=&amp;NewUserName='+uid+'&amp;DomainName=21cn.com&amp;submit.x=33&amp;submit.y=10'+CRLF+<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'Content-Length: '+inttostr(length(PostStr))+CRLF+CRLF;<br>&nbsp; strcopy(DataBuf,pchar(HeadStr+PostStr+CRLF));<br>&nbsp; err:=send(FSocket,DataBuf,strlen(DataBuf),MSG_DONTROUTE);<br>&nbsp; strcopy(DataBuf,pchar(''));<br>&nbsp; repeat<br>&nbsp; &nbsp; err:=recv(FSocket,TmpBuf,MaxSize,0);<br>&nbsp; &nbsp; strcopy(DataBuf,pchar(strpas(DataBuf)+strpas(TmpBuf)));<br>&nbsp; until err&lt;=0;<br>&nbsp; strcopy(SubStr,pchar('你已经成功'));<br>&nbsp; if AnsiStrPos(DataBuf,SubStr)&lt;&gt;nil then WriteCaption(hEditEMail,pchar('申请成功!'));<br>&nbsp; //WriteCaption(hEditCount,pchar(inttostr(strlen(DataBuf))));<br>&nbsp; StopNet(Fsocket);<br>end;<br><br>//------------------------------------<br>//以下是线程创建时调用的线程函数<br>function fun(Parameter: Pointer): Integer; stdcall;<br>var<br>&nbsp; uid,pid:string;<br>begin<br>&nbsp; &nbsp; ReadCaption(hEditEmail,sbuf);uid:=strpas(sbuf);<br>&nbsp; &nbsp; ReadCaption(hEditCount,sbuf);pid:=strpas(sbuf);<br>&nbsp; &nbsp; PostData(uid,pid);<br>&nbsp; &nbsp; result:=0;<br>end;<br><br><br>
 
用AHM控件,然后用ASPACK压缩,程序可能很小,100K左右吧。<br>——iseek
 
用winapi创建socket连接,端口26,掌握对应的命令(echo)<br>具体请查delphi6的idsmtp控件,做的好的话&lt;100k(大约50k)。
 
to jingtao<br>看了一个月,还是不懂:(,能否详细解释一下:)),注册用户和邮件发送程序技术一样?<br><br>to Darking<br>能否详细介绍一下呢?<br><br>to all<br>谢谢各位了
 
我手头有一个pcmail,它就只有11K.<br>不过我没有成功使用过,可能要用它9X上.
 
Lera<br>你的pcmail,是什么东西?是控件,源程序,应用程序?
 
下载一个smth的控件,这方面的控件很多,<br>然后用纯win 32 api编程,窗口之类的东西全部自己创建,<br>动态加入这个控件,可以令源程序很小。100多k完全可能。
 
PCMAIL是一个用汇编写的邮件程序,现在可能没有什么用途,毕业它的功能有限。<br>下载:http://asm.yeah.net,即罗云彬的编程世界里面有它的例子,<br>如找不到,给我个Email,发给你。
 
用 ASP 做个不是很小吗?
 
锦涛讲的是如何用API而不用TCUSTOMWINSOCKET来建立和读写SOCKET<br>而HN-HUANG却在问SMTP的协议?<br>你如果真有1个月时间看,就去看RFC 821,<br>如果知道了如何用API处理SOCKET,又知道了SMTP的原理<br>你完全可以20K以下搞定(不要USES SYSUTILS AND CLASSES)<br><br>随便找了个RFC的引用:http://www.freesoft.org/CIE/RFC/821/index.htm<br>
 
同意楼上<br>昨天晚上我看来一篇关于用PHP发邮件的文章<br>在phpuser(破坏派中文用户站)有<br>关于mime邮件的发送将的很好<br>可以参考
 
用java写, 不到10K就搞定
 
多人接受答案了。
 
后退
顶部