d7+indy10,做发邮件,为何出现 “authen tication is required”,如何才能解决?(25分)

  • 主题发起人 主题发起人 51zhan.com
  • 开始时间 开始时间
5

51zhan.com

Unregistered / Unconfirmed
GUEST, unregistred user!
具体的错误详细信息为:
---------------------------
Debugger Exception Notification
---------------------------
Project SfMail.exe raised exception class EIdSMTPReplyError with message 'authentication is required,mx13,wKjANLArSgCdPH9FyPaWGg==.32169S3 1165966493
'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------




unit teml; interface
uses Windows,Classes,Sysutils,Dialogs,
IdSMTP,IdMessage,IdDNSResolver;
type TEMAIL=class(TObject)
private
function GetMxList(dns,dmn:string):TstringList;
function EmailAddrTest(a:string):boolean;
function EmailGetDomain(a:string):string;
function EmailGetName(a:string):string;
public
function EMS(vto,vfrom,vname,vsub:string;vbody:TstringList):boolean;
function NamelessEMS(vto,vsub:string;vbody:tstringlist):boolean;
end;
var EMAIL:TEMAIL;

implementation

function TEMAIL.EmailAddrTest(a:string):boolean;
var s:string; k,n,p:INTEGER;
begin
Result := false; if length(a)<5 then exit;
p := pos('@',a); if (p=0)or(p=length(a))or(p=1) then exit;
n := 0;
for k := 1 to length(a) do if a[k]='@' then inc(n);
if n<>1 then exit;
Result := true;
end;

function TEMAIL.EmailGetDomain(a:string):string;
var p:INTEGER;
begin
Result := '';
if not EmailAddrTest(a) then exit;
p := pos('@',a);
Result := COPY(a,p+1,Length(a)-p);
end;

function TEMAIL.EmailGetName(a:string):string;
var p:INTEGER;
begin
Result := '';
if not EmailAddrTest(a) then Exit;
p := POS('@',a);
Result := COPY(a,1,p-1);
end;

function TEMAIL.EMS(vto,vfrom,vname,vsub:string;vbody:TstringList):boolean;
var Smtp:TIdSmtp;
Msg:TIdMessage;
s,sMX,sDomain:string; k,m,p:INTEGER;
MX:TstringList;
begin
Result := false;
if not (EmailAddrTest(vto) and EmailAddrTest(vfrom)) then Exit;
sDomain:=EmailGetDomain(vto);
if sDomain='' then Exit;
MX := GetMxList('',sDomain);
if MX.Count<1 then begin MX.Free; end;
sMX := MX[0]; MX.Free;

Msg := TIdMessage.Create(NIL);
Msg.Subject := vsub;
Msg.Body.Addstrings(vbody);
Msg.Recipients.EMailAddresses := vto;
Msg.From.Address := vfrom;
Msg.From.Name := vname;

Smtp := TIdSmtp.Create(NIL);
Smtp.Host := sMX; SMTP.ReadTimeout:=5000;
try Smtp.Connect(5000) except
on E:Exception do begin Smtp.Free; Msg.Free; Exit; end;
end;
if not Smtp.Connected then begin Smtp.Free; Msg.Free; Exit; end;
try Smtp.Send(Msg) except
on E:Exception do begin Smtp.Disconnect; Smtp.Free; Msg.Free; Exit; end;
end;
Smtp.Disconnect; Smtp.Free; Msg.Free;
Result := true;

end;


function TEMAIL.GetMxList(dns,dmn:string):TstringList;
var k: Integer; IdDNS:TIdDnsResolver;
begin
Result := TstringList.Create;
IdDNS := TIdDnsResolver.Create(NIL);
if dns='' then dns := '202.102.128.68';
IdDNS.Host := dns;
IdDns.QueryRecords := [qtMX];
try IdDns.Resolve(dmn);
IdDns.Active;
for k := 0 to IdDns.QueryResult.Count-1 do if IdDns.QueryResult[k] IS TMxRecord then Result.Add(TMXRecord(IdDns.QueryResult[k]).ExchangeServer);
finally IdDns.Free;
end;
end;

function TEMAIL.NamelessEMS(vto,vsub:string;vbody:tstringlist):boolean;
begin
Result:=EMS(vto,'ems@ems.com','EMS',vsub,vbody);
end;

Initialization
EMAIL := TEMAIL.Create;
end.
 
authentication is required...需要登录认证
 
为何在d6+和自带的indy这样写就不需要登陆验证,有解决办法?
 
用D7+indy9!
我用indy10也提示有问题,后来不用了!
 
不管是indy9,还是indy10,我参照论坛上改了,还是不行啊,怎么办?哪位大哥解决了啊,告诉我一下。
 
用indy10,利用SINA的SMTP为何总是发送不了?


IdSMTP1.Host := 'smtp.sina.com.cn';//'';//smtp.sina.com.cn'mx.mail.163.split.netease.com';////SMTP.163.com服务器Rs`7`@
IdSMTP1.Port :=25;//服务器端口W63gO8
IdSMTP1.AuthType := atDefault ;
IdSMTP1.Username:='wangchw78@sina.com';//在SMTP.163.com服务器上的用户名ID1
IdSMTP1.Password := '111111';//在SMTP.163.com服务器上的密码#?E

try
IdSMTP1.Connect;//建立连接d.
except
Showmessage('连接SMTP服务器失败!');
Exit;
end;
try
try
with IdMessage1 do
begin
body.Clear;
Body.add('用户名及密码123');//邮件正文件内容,也可这样Body.Assign(memo1.lines);X+
From.address :='ah_wcw@163.com';//发件人名GY
Recipients.EMailAddresses :='wangchw78@sina.com';//收件人邮箱:&quot;
Subject:='用户名及密码';//邮件标题dw{d{
end;

IdSMTP1.Send(IdMessage1);//发送邮件7c&quot;Xy
showmessage('您的信件已成功发送');
except
end;
finally

IdSMTP1.Disconnect;//断开连接^DpX
end;
 
换sohu的信箱试。我记得有人说过,163的信箱屏蔽indy
 
>>authentication is required...
这是说需要登录认证
 
后退
顶部