Re: Catching EIdSMTPReplyError exception

Giganews Newsgroups
Subject: Re: Catching EIdSMTPReplyError exception
Posted by:  Remy Lebeau (re…@lebeausoftware.org)
Date: Mon, 19 Mar 2012

Clément wrote:

> I added the ##Newcode line hoping to get some more precise information
> The fact is that when I run the application in debug mode + delphi IDE
> I get a
> nice error explaining what's happening,i.e :
> "raised exception class EIdSMTPReplyError with message 'Este dominio
> nao esta autorizado para enviar emails sem autenticacao, para enviar
> emails basta autenticar sua senha clicando no botao eao Enviar/receber
> de seu programa de email. Opcionalmente e possivel eliminar este erro
> alterando a porta do SMTP de 25 para 2525 e marcando a opcao meu
> Servidor Requer Autenticacao"
>
> But I only manage to catch an 'Authorization failed (5.'.
>
> How can I get the detailed error?

The information you are looking for is in the Exception object, not the TIdSMTP
object.  You are already accessing the value that the IDE displays - it is
displaying the Exception.Message property.  However, EIdSMTPReplyError has
some additional error information that the IDE does not display.  It is in
the EIdSMTPReplyError.EnhancedCode property.  I would suggest something more
like this:

{code:delphi}
try
  FSMTP.Connect(aHost, aPort);
  FSMTP.Send(eMsg);
except
  on e: EIdSMTPReplyError do begin
    if e.EnhancedCode.Available then begin
      aErrMsg := e.Message + #13#10 + '--' + #13#10 + e.EnhancedCode.ReplyAsStr;
    end else begin
      aErrMsg := e.Message;
    end;
  end;
  on e: Exception do begin
    aErrMsg := e.Message;
  end;
end;
{code}

Or:

{code:delphi}
try
  FSMTP.Connect(aHost, aPort);
  FSMTP.Send(eMsg);
except
  on e: Exception do begin
    aErrMsg := e.Message;
    if (e is EIdSMTPReplyError) and EIdSMTPReplyError(e).EnhancedCode.Available
then begin
      aErrMsg := aErrMsg + #13#10 + '--' + #13#10 + EIdSMTPReplyError(e).EnhancedCode.ReplyAsStr;
    end;
  end;
end;
{code}

--
Remy Lebeau (Indy Team)

Replies

None

In response to

Catching EIdSMTPReplyError exception posted by Clément_Doss on Sat, 17 Mar 2012