السلام عليكم
هذه طريقة لارسال e-mail باستخدام smtp أتمنى ان تكون مفيدة .
أود ان أشكر njhhack,shellapi
uses
winsock;
const
CRLF=#13#10;
var
err:integer;
fromstr,sendtostr,subjectstr,contentstr:string;
function StartNet(host:string;port:integer):integer;
var
wsadata:twsadata;
fsocket:integer;
SockAddrIn:TSockAddrIn;
errs:integer;
begin
//using winsock v1.1
err:=WSAStartup($0101,WSAData);
//create client socket using SOCK_STREAM ( TCP protocol )
FSocket := socket(PF_INET, SOCK_STREAM,IPPROTO_IP);
//initial data
SockAddrIn.sin_addr.s_addr:=inet_addr(PChar(host));
SockAddrIn.sin_family := PF_INET;
SockAddrIn.sin_port :=htons(port);
//client connect to smtp server
repeat
errs:=connect(FSocket,SockAddrIn, SizeOf(SockAddrIn));
until errs=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
//receives data from a socket
err:=recv(FSocket,DataBuf,MaxSize,0);
//sends data on a connected socket
strcopy(DataBuf,pchar(SendStr));
err:=send(FSocket,DataBuf,strlen(DataBuf),MSG_DONTROUTE);
Result:=0;
end;
procedure SendMail;
var
SendBody:string;
FSocket:integer;
begin
//specify smtp server address
//here we use smtp.21cn.com
//its ip:202.104.32.230
//specify smtp server send mail port ,default port 25
FSocket:=StartNet('202.104.32.230',25);
//send mail process steps
//------------------------------------------------
// Step 1: send helo command (start to send mail)
SendData(FSocket,'HELO'+CRLF);
// password verify
//I didn't use it in my program
{
SendData(FSocket,'AUTH LOGIN'+CRLF);
SendData(FSocket,'Encodebase64(Esmtp username)'+CRLF);
SendData(FSocket,'Encodebase64(Esmtp password)'+CRLF);
}
// Step 2 : send "mail from" command (sender email)
// we should use a legal user name in the smtp server
//otherwise the server will not allow sending process .
// here we use "hack@21cn.com"
SendData(FSocket,'MAIL FROM: <hack@21cn.com>'+CRLF);
//hack@21cn.com
// Step 3:
//send "RCTP TO "command (target E-mail )
SendData(FSocket,'RCPT TO: <'+dest+'>'+CRLF);
// Step 4: send "DATA" command.
//(will start to send data to smtp server )
SendData(FSocket,'DATA'+CRLF);
// Step 5:send concret data including the following
// From : you can write anything you want .
// To : you can write anything you want
// Subject:the message title and body .
// at the end "." and "CRLF"
SendBody:='From:"' +fromstr+'"<'+fromstr+'>'+CRLF
+'To:" '+Sendtostr+'"<'+Sendtostr+'>'+CRLF
+'Subject:'+Subjectstr+CRLF
+CRLF
+Contentstr+CRLF
+'.'+CRLF;
SendData(FSocket,SendBody);
//send QUIT command .
SendData(FSocket,'QUIT'+CRLF);
StopNet(Fsocket);
end;تخيل ارسال 1000 رسالة إلى e-mail ما .....