用NMSMTP即可,注意重载对应的OnConnect函数 unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Psock, NMsmtp;type TForm1 = class(TForm) NMSMTP1: TNMSMTP; Button1: TButton; procedure Button1Click(Sender: TObject); procedure NMSMTP1Connect(Sender: TObject); private { Private declarations } public { Public declarations } end; const BaseTable:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject); begin //在此之前要初始化对应的NMSMTP1得相关内容 NMSMTP1.PostMessage.Date:=DateTimeToStr(Now); NMSMTP1.Connect; NMSMTP1.SendMail; NMSMTP1.Disconnect; 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;procedure TForm1.NMSMTP1Connect(Sender: TObject); begin if nmsmtp1.ReplyNumber = 250 then nmsmtp1.Transaction('auth login'); if nmsmtp1.ReplyNumber =334 then nmsmtp1.Transaction(EncodeBase64(YourUserName)); if nmsmtp1.ReplyNumber =334 then nmsmtp1.Transaction(EncodeBase64(YourPassWord));end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Psock, NMsmtp;type
TForm1 = class(TForm)
NMSMTP1: TNMSMTP;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure NMSMTP1Connect(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const BaseTable:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
//在此之前要初始化对应的NMSMTP1得相关内容
NMSMTP1.PostMessage.Date:=DateTimeToStr(Now);
NMSMTP1.Connect;
NMSMTP1.SendMail;
NMSMTP1.Disconnect;
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;procedure TForm1.NMSMTP1Connect(Sender: TObject);
begin
if nmsmtp1.ReplyNumber = 250 then
nmsmtp1.Transaction('auth login');
if nmsmtp1.ReplyNumber =334 then
nmsmtp1.Transaction(EncodeBase64(YourUserName));
if nmsmtp1.ReplyNumber =334 then
nmsmtp1.Transaction(EncodeBase64(YourPassWord));end;end.