implementation {$R *.dfm} { R RUNEXE.RES} //BaseTable为BASE64码表 const BaseTable:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';///////////发送 邮件部分 开始//////////////////////////////////////// function TForm1.SendMail_ID(BodyText,ToAddressTxt:string):boolean; //var MailTo,MailBody:TStringList; begin result:=false; with Nmsmtp1 do begin try mSuccess :=false; Host :='smtp.126.com';//SMTP 服务器 Port :=25; //SMTP 服务器 端口 UserID :='tel139'; //发信人的用户名,必须是真实的 ReportLevel :=1; TimeOut :=10000; Connect ; ///连接 if AuthSucc=true then//验证成功 with nmsmtp1.PostMessage do begin FromAddress :='[email protected]'; //发 信人的电子邮件地址 ToAddress.Text :='[email protected]'; //收 信人的电子邮件地址 Body.Text :=mBodyText; //邮件正文 Subject :='邮件标题; //邮件标题 end; SendMail; //发送邮件 result:=true; except Cancel; end;//try end;//Nmsmtp1 end;procedure TForm1.NMSMTP1Connect(Sender: TObject); begin //////连接成功,下面用户认证过程 with Nmsmtp1 do begin try if ReplyNumber = 250 then Transaction('auth login'); //开始认证 if ReplyNumber =334 then //返回值为334,让你输入用BASE64编码后的用户名 Transaction(EncodeBase64('tel139')); if ReplyNumber =334 then // 返回值为334,让你输入用BASE64编码后的用户密码 Transaction(EncodeBase64('123456')); if ReplyNumber =235 then //验证成功 AuthSucc:=true; except Cancel; end;//try end; end;procedure TForm1.NMSMTP1Success(Sender: TObject); begin mSuccess:=true;//发送成功 end;////////Base64///编码//////////////// function FindInTable(CSource:char):integer; begin result:=Pos(string(CSource),BaseTable)-1; end; ////function DecodeBase64(Source:string):string; var SrcLen,Times,i:integer; x1,x2,x3,x4,xt:byte; begin result:=''; SrcLen:=Length(Source); Times:=SrcLen div 4; for i:=0 to Times-1 do begin x1:=FindInTable(Source[1+i*4]); x2:=FindInTable(Source[2+i*4]); x3:=FindInTable(Source[3+i*4]); x4:=FindInTable(Source[4+i*4]); x1:=x1 shl 2; xt:=x2 shr 4; x1:=x1 or xt; x2:=x2 shl 4; result:=result+chr(x1); if x3= 64 then break; xt:=x3 shr 2; x2:=x2 or xt; x3:=x3 shl 6; result:=result+chr(x2); if x4=64 then break; x3:=x3 or x4; result:=result+chr(x3); end; end; /////function EncodeBase64(Source:string):string; var Times,LenSrc,i:integer; x1,x2,x3,x4:char; xt:byte; begin result:=''; LenSrc:=length(Source); if LenSrc mod 3 =0 then Times:=LenSrc div 3 else Times:=LenSrc div 3 + 1; for i:=0 to times-1 do begin if LenSrc >= (3+i*3) then begin x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1]; xt:=(ord(Source[1+i*3]) shl 4) and 48; xt:=xt or (ord(Source[2+i*3]) shr 4); x2:=BaseTable[xt+1]; xt:=(Ord(Source[2+i*3]) shl 2) and 60; xt:=xt or (ord(Source[3+i*3]) shr 6); x3:=BaseTable[xt+1]; xt:=(ord(Source[3+i*3]) and 63); x4:=BaseTable[xt+1]; end else if LenSrc>=(2+i*3) then begin x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1]; xt:=(ord(Source[1+i*3]) shl 4) and 48; xt:=xt or (ord(Source[2+i*3]) shr 4); x2:=BaseTable[xt+1]; xt:=(ord(Source[2+i*3]) shl 2) and 60; x3:=BaseTable[xt+1]; x4:='='; end else begin x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1]; xt:=(ord(Source[1+i*3]) shl 4) and 48; x2:=BaseTable[xt+1]; x3:='='; x4:='='; end; result:=result+x1+x2+x3+x4; end; end;//////////
绝对 不错的 哦
[email protected]
{$R *.dfm}
{ R RUNEXE.RES}
//BaseTable为BASE64码表
const BaseTable:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';///////////发送 邮件部分 开始////////////////////////////////////////
function TForm1.SendMail_ID(BodyText,ToAddressTxt:string):boolean;
//var MailTo,MailBody:TStringList;
begin
result:=false;
with Nmsmtp1 do
begin
try
mSuccess :=false;
Host :='smtp.126.com';//SMTP 服务器
Port :=25; //SMTP 服务器 端口
UserID :='tel139'; //发信人的用户名,必须是真实的
ReportLevel :=1;
TimeOut :=10000;
Connect ; ///连接
if AuthSucc=true then//验证成功
with nmsmtp1.PostMessage do
begin
FromAddress :='[email protected]'; //发 信人的电子邮件地址
ToAddress.Text :='[email protected]'; //收 信人的电子邮件地址
Body.Text :=mBodyText; //邮件正文
Subject :='邮件标题; //邮件标题
end;
SendMail; //发送邮件
result:=true;
except
Cancel;
end;//try
end;//Nmsmtp1
end;procedure TForm1.NMSMTP1Connect(Sender: TObject);
begin
//////连接成功,下面用户认证过程
with Nmsmtp1 do
begin
try
if ReplyNumber = 250 then
Transaction('auth login'); //开始认证
if ReplyNumber =334 then //返回值为334,让你输入用BASE64编码后的用户名
Transaction(EncodeBase64('tel139'));
if ReplyNumber =334 then // 返回值为334,让你输入用BASE64编码后的用户密码
Transaction(EncodeBase64('123456'));
if ReplyNumber =235 then //验证成功
AuthSucc:=true;
except
Cancel;
end;//try
end;
end;procedure TForm1.NMSMTP1Success(Sender: TObject);
begin
mSuccess:=true;//发送成功
end;////////Base64///编码////////////////
function FindInTable(CSource:char):integer;
begin
result:=Pos(string(CSource),BaseTable)-1;
end;
////function DecodeBase64(Source:string):string;
var
SrcLen,Times,i:integer;
x1,x2,x3,x4,xt:byte;
begin
result:='';
SrcLen:=Length(Source);
Times:=SrcLen div 4;
for i:=0 to Times-1 do
begin
x1:=FindInTable(Source[1+i*4]);
x2:=FindInTable(Source[2+i*4]);
x3:=FindInTable(Source[3+i*4]);
x4:=FindInTable(Source[4+i*4]);
x1:=x1 shl 2;
xt:=x2 shr 4;
x1:=x1 or xt;
x2:=x2 shl 4;
result:=result+chr(x1);
if x3= 64 then break;
xt:=x3 shr 2;
x2:=x2 or xt;
x3:=x3 shl 6;
result:=result+chr(x2);
if x4=64 then break;
x3:=x3 or x4;
result:=result+chr(x3);
end;
end;
/////function EncodeBase64(Source:string):string;
var
Times,LenSrc,i:integer;
x1,x2,x3,x4:char;
xt:byte;
begin
result:='';
LenSrc:=length(Source);
if LenSrc mod 3 =0 then
Times:=LenSrc div 3
else
Times:=LenSrc div 3 + 1;
for i:=0 to times-1 do
begin
if LenSrc >= (3+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(Ord(Source[2+i*3]) shl 2) and 60;
xt:=xt or (ord(Source[3+i*3]) shr 6);
x3:=BaseTable[xt+1];
xt:=(ord(Source[3+i*3]) and 63);
x4:=BaseTable[xt+1];
end
else if LenSrc>=(2+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(ord(Source[2+i*3]) shl 2) and 60;
x3:=BaseTable[xt+1];
x4:='=';
end else
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
x2:=BaseTable[xt+1];
x3:='=';
x4:='=';
end;
result:=result+x1+x2+x3+x4;
end;
end;//////////