1.IdSMTP设置了错误的username或password或Address,正确的Host,但是connect不报错
2.IdSmtp.send(IdMessage)也不报错
3.bflag := IdSMTP1.Authenticate();报错,为什么?如何才能验证设置是错误的,邮件实际上没收到呢,我希望能检测出没收到邮件,而弹出一个错误框。谢谢。着急

解决方案 »

  1.   

    //这是我在校时写过的一段,当时测试是可以发送的.
    //"TIdAttachment.Create(IdMessage1.MessageParts,MailAttachmentEdit.Text);"这句是
    //增加附件
    procedure TForm11.BtnSendMailClick(Sender: TObject);
    begin
        IdSMTP1.AuthenticationType:=atLogin;
        IdSMTP1.Host:=MailServerCombo.Text;
        IdSMTP1.Port:=25;
        IdMessage1.From.Address:=MailFromEdit.Text;
        IdSMTP1.Username:=MailUsernameEdit.Text;
        IdSMTP1.Password:=MailPasswordEdit.Text;    IdMessage1.Recipients.EMailAddresses:=MailToEdit.Text;    IdMessage1.Subject:=MailSubjectEdit.Text;
        IdMessage1.Body.Text:=MailBodyMemo.Text;    if FileExists(MailAttachmentEdit.Text) then
           TIdAttachment.Create(IdMessage1.MessageParts,MailAttachmentEdit.Text);
           
        try
          try
            BtnSendMail.Enabled:=false;
            IdSMTP1.Connect(1000);
            IdSMTP1.Send(IdMessage1);
            Application.MessageBox('您的邮件已经成功发送到目标邮箱!','成功',mb_ok+mb_iconinformation);
          except on E:Exception do
            StatusBar1.Panels[0].Text:=(E.Message);
          end;
        finally
          if IdSMTP1.Connected then
            IdSMTP1.Disconnect;
          BtnSendMail.Enabled:=True;
        end;
    end;