向高手求助!!NMSMTP控件中的认证函数:nmsmtp.verify(s:string) 参数s的内容是什么?

唐巧 2003-01-22 04:44:00
我不知道这个内容应该填什么?我试了一下用户名,密码,都失败了。
请帮帮我。
...全文
34 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tryway 2003-04-24
  • 打赏
  • 举报
回复
下面是我写的一段程序:
unit frmSendEMail;

interface

uses
Windows, NMsmtp, classes, Sysutils, Forms;

type
Tevendesc = class
private
class procedure NMSMTPConnect(Sender: TObject);
end;

function SendM_E_Mail(Host: String; Port: Integer; FromAddress: String; ToAddressList: TStringList;
aUserName, aPassword: string; Subject: String = ''; Body: TStringList = nil): Boolean;
function SendA_E_Mail(Host: String; Port: Integer; FromAddress: String; ToAddress: String;
aUserName, aPassword: string; Subject: String = ''; Body: TStringList = nil): Boolean;

implementation

const
BaseTable = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var
fNMSMTP: TNMSMTP;
fUserName, fPassword: String;

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;

function GeneralFromEmailAddress(aHost: String; aUserName: String): String;
var
iPos: Integer;
tempString: String;
begin
Result := '';
if Pos('.', aHost) > 0 then
tempString := Copy(aHost, Pos('.', aHost) + 1, Length(aHost) - Pos('.' , aHost));
if Pos('.', tempString) > 0 then
tempString := Copy(tempString, Pos('.', tempString) + 1, Length(tempString) - Pos('.' , tempString));
if Pos('.', tempString) > 0 then
Exit;
iPos := Pos('.', aHost);
if iPos > 0 then
begin
Result := aUserName + '@' + Copy(aHost, iPos + 1, Length(aHost) - iPos);
end;
end;

procedure SetHost(aNMSMTP: TNMSMTP; Host: String; Port: Integer; UserID: String);
begin
aNMSMTP.Host := Host;
aNMSMTP.Port := Port;
if UserID <> '' then
aNMSMTP.UserID := UserID;
aNMSMTP.TimeOut := 1000;
aNMSMTP.OnConnect := Tevendesc.NMSMTPConnect;
end;

procedure SetConnection(aNMSMTP: TNMSMTP);
begin
if not aNMSMTP.Connected then
aNMSMTP.Connect;
end;

procedure SetAndSendMail(aNMSMTP: TNMSMTP; FromAddress: String;
Subject: String = ''; Body: TStringList = nil);
begin
//if (aNMSMTP.ReplyNumber = 235) or (aNMSMTP.ReplyNumber = 500) or (fUserName = '') then
//begin
try
aNMSMTP.Charset := 'GB2312_CHARSET ';
aNMSMTP.PostMessage.FromAddress := FromAddress;
aNMSMTP.PostMessage.Subject := Subject;
if Body <> nil then
aNMSMTP.PostMessage.Body.Text := Body.Text;
aNMSMTP.PostMessage.Date := DateToStr(Now());
aNMSMTP.SendMail;
if aNMSMTP.Connected then
aNMSMTP.Disconnect;
except

end;
//end;
if (aNMSMTP.ReplyNumber <> 235) and (fUserName = '') then
;//Application.MessageBox('', '', 0);
end;

function SendM_E_Mail(Host: String; Port: Integer; FromAddress: String; ToAddressList: TStringList;
aUserName, aPassword: string; Subject: String = ''; Body: TStringList = nil): Boolean;
var
aFromAddress: String;
begin
fUserName := aUserName;
fPassword := aUserName;
fNMSMTP := TNMSMTP.Create(nil);
try
try
SetHost(fNMSMTP, Host, Port, aUserName);
SetConnection(fNMSMTP);
fNMSMTP.PostMessage.ToAddress.Text := ToAddressList.Text;
aFromAddress := GeneralFromEmailAddress(Host, fUserName);
if aFromAddress = '' then
aFromAddress := FromAddress;
SetAndSendMail(fNMSMTP, aFromAddress, Subject, Body);
Result := True;
except
Result := False;
end;
finally
fNMSMTP.Free;
end;
end;

function SendA_E_Mail(Host: String; Port: Integer; FromAddress: String; ToAddress: String;
aUserName, aPassword: string; Subject: String = ''; Body: TStringList = nil): Boolean;
var
aFromAddress: String;
begin
fUserName := aUserName;
fPassword := aPassword;
fNMSMTP := TNMSMTP.Create(nil);
try
try
SetHost(fNMSMTP, Host, Port, aUserName);
SetConnection(fNMSMTP);
fNMSMTP.PostMessage.ToAddress.Text := ToAddress;
aFromAddress := GeneralFromEmailAddress(Host, fUserName);
if aFromAddress = '' then
aFromAddress := FromAddress;
SetAndSendMail(fNMSMTP, aFromAddress, Subject, Body);
Result := True;
except
Result := False;
end;
finally
fNMSMTP.Free;
end;
end;

{ Tevendesc }

class procedure Tevendesc.NMSMTPConnect(Sender: TObject);
begin
if fNMSMTP.ReplyNumber <> 500 then
begin
if fNMSMTP.ReplyNumber = 250 then
fNMSMTP.Transaction('auth login');//开始认证
if fNMSMTP.ReplyNumber = 334 then
begin
fNMSMTP.Transaction(EncodeBase64(fUserName)); // 处理用户名
fNMSMTP.Transaction(EncodeBase64(fPassword)); // 处理密码
end;
end;
end;

end.
pillarlu 2003-01-29
  • 打赏
  • 举报
回复
可以用Indy Clients 下的IdSmtp组件,它带有身份验证的功能。不过它发送邮件比NMSmtp稍微麻烦一点哦,还要加其他的辅助组件。
唐巧 2003-01-22
  • 打赏
  • 举报
回复
失望极了。。。。
整整半个小时。。。。没人回答。
我不会再来这儿了。88

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧