发送邮件中的问题?(50分)

E

endsky

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button2Click(Sender: TObject);
var
AMsg :TIdMessage;
SMTP: TIdSMTP;
begin
AMsg :=TIdMessage.Create(self);
with AMsgdo
begin
Body.Text :='这里是信件内容';
From.Text :='lixh99@126.com';
Recipients.EMailAddresses := 'lixh1999@163.com';
{收件人地址}
Subject := 'test';
{ 标题 }
Priority := TIdMessagePriority(1);
{ 优先级 }
CCList.EMailAddresses := '';
{ 抄送 }
BccList.EMailAddresses := '';
{ 暗送 }
ReceiptRecipient.Text := 'lixh99@126.com';
SMTP.Authen
ticationType := atLogin;
SMTP.Username:= 'lixh99';
SMTP.Password := '888888';
{General setup}
SMTP.Host := 'smtp.126.com';
SMTP.Port := 25;
SMTP.Connect();
try
SMTP.Send(AMsg);
finally
SMTP.Disconnect;
end;
AMsg.Free();
showmessage('过程完成,如果没有出错,估计是成功啦');
end;
end;
报错:Project Project2.exe raised excepton class EIdProtocoReplyError with message "bad sequence of commands"
求大家帮忙呀!
开始我用的是新浪邮箱,因为ping不通'smtp.sina.com',所以改为126邮箱发送邮件
 
有人告诉你:
SMTP.Host := 'smtp.126.com';
SMTP.Port := 25;
吗,不是其他的吗?
 
SMTP.Port := 25 没错
 
SMTP.Connect();
try
SMTP.Authen
ticate;//加上这句。
SMTP.Send(AMsg);
finally
SMTP.Disconnect;
end;

注:在Send方法中,首先会发送'RSET'命令,并且判断是否需要验证,如果需要验证,
并且没有验证的情况下,发送'AUTH LOGIN'命令进行验证。我试着将发送'RSET'命令
的语句'SendCmd('RSET')'去掉之后,就正常了,而楼主的错误是在发送'AUTH LOGIN'
命令之后引发的,所以我推测该服务器是不允许在'RSET'命令之后再进行验证的。
所以,解决的方法就是,Connect之后立即进行验证。
 
出现了新的错误:Requested action not taken :local user only ,smtp3,wkgaobqahq+netere5iz7ea==.21831s3
 
调试一下,具体在哪个步骤出错,我这边Indy90,经过上述的修改,
是可以正常对126邮箱发邮件的。
 
我这是delphi7自带的,我下个试看,谢谢
 
我这边是delphi7 它自带的控件Indy是9.0版本
SMTP.Send(AMsg);运行这步出现错误:Requested action not taken :local user only ,smtp3,wkgaobqahq+netere5iz7ea==.21831s3
 
SMTP.Connect();
try
SMTP.Authen
ticate;//加上这句。
SMTP.Send(AMsg);
finally
SMTP.Disconnect;
end;
,楼主这个可以的呀,你是不是其它的地方还不行呀
 
SMTP.Send(AMsg);
就是运行到这步出错!
 
SMTP.Send(AMsg);是不是这一步前面有什么属性没有设置好,盼大家指点!
 
发送(SMTP)邮件范例
function SendMail2SMS(ServerHost: string;
ServerPort: Integer;
UserName, Password, PhoneNo, MsgContent: string): Boolean;
var
IdSMTP: TIdSMTP;
IdMsg: TIdMessage;
begin

try
IdSMTP := TIdSMTP.Create(nil);
IdMsg := TIdMessage.Create(nil);
try
IdSMTP.Authen
ticationType := atLogin;
//服务器需要身份验证
IdSMTP.Host := ServerHost;
IdSMTP.Port := ServerPort;
IdSMTP.Username := UserName;
IdSMTP.Password := Password;
IdSMTP.Connect();

IdMsg.Subject := MsgContent;
with IdMsg.Recipients.Adddo
begin

Address := PhoneNo + '@sms.com';
//加上邮件服务器域名
end;

IdMsg.From.Address := UserName + '@sms.com';
IdSMTP.Send(IdMsg);

Result := True;
finally
IdSMTP.Disconnect;
IdSMTP.Free;
IdMsg.Free;
end;

except
Result := False;
end;

end;


函数调用方法:
if not SendMail2SMS('127.0.0.1', 25, 'zs', '000', '13500000000', '你好,测试短信!') then

ShowMessage('提交短信失败!')
else

ShowMessage('提交短信成功!');
 
用上这个
1、
找到procedure TIdSMTP.Send(AMsg: TIdMessage);这个函数将SendCmd('RSET');这行注销
2、IdMessageCoderMIME这个单元,将下面的常量IndyMIMEBoundary,IndyMultiPartAlternativeBoundary,IndyMultiPartRelatedBoundary改成你自己需要的就可以了。
在你project所在文件夹中新建一个文件夹,将IdMessageClient.pas,IdSMTP,IdMessageCoderMIME.pas这两个文件copy到这个新建的文件夹中,然后按我所说的方法修改这两个文件,最后在IDE中打开Project->Options->Directories/Conditionals->Search path中加入这个新建的文件夹所在的路径,重新编译就可以了。
 
还是这一步出现错误:SMTP.Send(AMsg);
是不是这一步前面有什么属性没有设置好或者网络问题,盼大家指点!
 
好的,我试下ProLove的方法
 
proLove:我按照你说的作了,它提示错误:You are not authorized to send mail, authen
tication is required
我已加上了这句:SMTP.Authen
ticate;//
 
那你有没有这个呀
if 需要审核 then
Smtp1.Authen
ticationType := atLogin
else
Smtp1.Authen
ticationType := atNone;
 
我第一种做法,是解决"bad sequence of commands",这个错误,
第二种是你那个SMPT需要验证才行的,所以你得加上
if 需要审核 then
Smtp1.Authen
ticationType := atLogin
else
Smtp1.Authen
ticationType := atNone;
 
现在可以发邮件了,但是出现了新的问题:
1,发到进度条30%时 抛出异常:project.exe raised exception class EIdProtocolReplyError with message,事后打开邮件发到邮箱里了
2,邮件是发到垃圾邮箱里。
 
楼上的,这个问题你查查邮件是否完善,能发就可以了,其他的对你来说,就应该很简单了吧
 
顶部