Re: Indy 9 and SMTP Authentification

Giganews Newsgroups
Subject: Re: Indy 9 and SMTP Authentification
Posted by:  Remy Lebeau \(Indy Team\) (re…@lebeausoftware.org)
Date: Wed, 27 Oct 2010

"Tom Hahn" <tha…@hahntech.com> wrote in message
news:1494043991309841610.189105thahn-hahntech.c…@news.atozed.com...

> I'm confused about how to do login authentication with Indy 9.

What is confusing exactly?  You already have the steps needed.

> Assuming that the AuthentificanType is set to atLogon, and
> the UserName and Password are entered,  should the following
> code be used (with error handling):

You do not need to call Authenticate() directly.  Send() calls it internally
for you.

{code:delphi}
SMTP.Connect;
try
  SMTP.Send;
finally
  SMTP.Disconnect;
end;
{code}

> Should there be a test to see if authenticated after Authenticate?

No.

> Does an authentication failure raise an error?

Yes.

> Is it possible to use SSL authentication with Indy 9?

Yes, but you have to do most of the work yourself to enable it.  Assign a
TIdSSLIOHandlerSocket component to the IOHandler property before calling
Connect(), and make sure the TIdSMTP.UseEHLO property is set to True.  Then
try the following code:

type
  TIdSMTPAccess = class(TIdSMTP)
  end;

var
  NameToSend: String;

SMTP.Connect;
try
  if SMTP.LastCmdResult.Text.IndexOf('STARTTLS') <> -1 then
  begin
    SMTP.SendCmd('STARTTLS', 220);
    TIdSSLIOHandlerSocket(SMTP.IOHandler).PassThrough := False;
    SMTP.AuthSchemesSupported.Clear;
    if Length(SMTP.HeloName) > 0 then begin
      NameToSend := SMTP.HeloName;
    end else begin
      NameToSend := SMTP.LocalName;
    end;
    if SMTP.SendCmd('EHLO ' + NameToSend) = 250 then begin
      TIdSMTPAccess(SMTP).GetAuthTypes;
    end;
  end;
  SMTP.Authenticate; // <-- optional
  SMTP.Send;
finally
  SMTP.Disconnect;
end;

--
Remy Lebeau (Indy Team)

Replies

In response to

Indy 9 and SMTP Authentification posted by Tom Hahn on Wed, 27 Oct 2010