关于NMSMTP控件问题 在利用NMSMTP控件发送信件时SMTP服务器要求用户验证,但是NMSMTP只有USERID属性没有PASSWORD属性改怎么办啊?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是啊,这个东西不带验证的,推荐采用INDY里的IDSMTP很好用的。 iamwind (2002-04-22 21:29:00) 在TNMSMTP的Connect事件中,发送"auth login"命令,如果返回"334",则发送Base64编码的用户名和密码,当返回"235"时验证成功。代码如下:const BaseTable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';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 NMSMTPConnect(Sender: TObject);var AuthOK: Boolean;begin AuthOK := False; NMSMTP.Transaction('auth login'); if NMSMTP.ReplyNumber <> 500 then begin if NMSMTP.ReplyNumber = 334 then begin NMSMTP.Transaction(EncodeBase64(EditUserName.Text)); // UserName NMSMTP.Transaction(EncodeBase64(EditPassword.Text)); // Password end; if NMSMTP.ReplyNumber = 235 then ShowMessage('验证成功!') else ShowMessage('验证失败!'); end else ShowMessage('该SMTP服务器无需用户验证。');end; 请大家帮忙看一下下面的代码,谢谢 要命,suipack5菜单的快捷键去不掉??? 模拟设计时组件托动、改变大小的问题?<等> 关于用ADO连接数据库的问题 能给BDE建的数据库加密吗? ### 在线等待!!! 如何使得窗口最大时覆盖任务栏? ### Query1.ParamByName('sno').value是什么意思? 如何一直显示功能提示 使用midas做的三层数据库系统,原来好好的,现在怎不行了?高手请指教! [续]2个字符串,取公有字符问题 在form 上有一个 panel 了,怎样新建一个 panel 使其具有前一个panel 的所有特性! 有没有获得当前月份上个月的函数???
则发送Base64编码的用户名和密码,当返回"235"时验证成功。
代码如下:
const
BaseTable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';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 NMSMTPConnect(Sender: TObject);
var
AuthOK: Boolean;
begin
AuthOK := False;
NMSMTP.Transaction('auth login');
if NMSMTP.ReplyNumber <> 500 then
begin
if NMSMTP.ReplyNumber = 334 then
begin
NMSMTP.Transaction(EncodeBase64(EditUserName.Text)); // UserName
NMSMTP.Transaction(EncodeBase64(EditPassword.Text)); // Password
end;
if NMSMTP.ReplyNumber = 235 then
ShowMessage('验证成功!')
else
ShowMessage('验证失败!');
end
else
ShowMessage('该SMTP服务器无需用户验证。');
end;