使用TIdSMTP发送邮件失败的问题,一直返回bad sequence of commands(30分)

  • 主题发起人 主题发起人 zepplin79
  • 开始时间 开始时间
Z

zepplin79

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> &nbsp;StatusMemo.Clear;<br> &nbsp;MailMessage.Clear;<br> //设置SMTP<br> &nbsp;SMTP.Host := HostEdit.Text;<br> &nbsp;SMTP.Port := 25;<br> &nbsp;SMTP.AuthenticationType :=atLogin;<br> &nbsp;SMTP.Username := UserNameEdit.Text;<br> &nbsp;SMTP.Password := PwdEdit.Text;<br> &nbsp;//设置邮件内容<br> &nbsp; MailMessage.From.Text := FromEdit.Text;<br> &nbsp; MailMessage.Recipients.EMailAddresses := ToEdit.Text;<br> &nbsp; MailMessage.Subject := SubjectEdit.Text;<br> &nbsp; MailMessage.Body.Assign(BodyMemo.Lines);<br><br> &nbsp; &nbsp;if FileExists(Attachment.Text) then<br> &nbsp; &nbsp; &nbsp;TIdAttachment.Create(MailMessage.MessageParts,Attachment.Text);<br><br> &nbsp; try<br> &nbsp; &nbsp;SMTP.Connect;<br> &nbsp; &nbsp;try<br> &nbsp; &nbsp;SMTP.Send(MailMessage);<br> &nbsp; &nbsp; &nbsp;ShowMessage('E-Mail 已寄出');<br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp;if SMTP.Connected then<br> &nbsp; &nbsp; &nbsp; &nbsp; SMTP.Disconnect;<br> &nbsp; &nbsp;end;<br> &nbsp;except<br> &nbsp; &nbsp;on e: exception do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;ShowMessage('Mail 寄送失敗:' + e.Message);<br> &nbsp; &nbsp; end;<br> &nbsp;end;<br><br>我单步跟踪了一下,SMTP服务器已经连上了,就是SMTP.send方法返回错误了,这是什么问题???
 
把finally改成except就可以了
 
我试了,这个可以<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=3359545
 
后退
顶部