Authentication not working

Giganews Newsgroups
Subject: Authentication not working
Posted by:  Carl Madigan (Carl_Madig…@pa.com.au)
Date: Wed, 08 Dec 2004

Hi all

I have a small client emailing test app that I'm trying to get SASL
Authentication working on.  When I send an email the username and
password don't seem to be used in the authentication as I can use an
incorrect password and the email still gets sent.  If I set the
Authentication type to atDefault and then set the username and password
on the TIdSMTP this works correctly.  Am I missing somthing simple?

Thanks for your help in advance

Cheers
Carl

procedure TForm1.Button1Click(Sender: TObject);
var
  E: olevariant;
  IdMsg : TIdMessage;
  CRAMMD5 : TIdSASLCRAMMD5;
begin
  IdMsg := TIdMessage.Create(nil);
  try
    IdMsg.Subject  := 'Sample Subject 4';
    IdMsg.Body.Text := 'Sample Body';
    IdMsg.Recipients.EmailAddresses := 'x…@xxx.net.au';

    with IdMsg.FromList.Add do
      begin
        User := 'Carlos';
        Address := 'x…@xxx.com.au';
      end;

    CRAMMD5 := TIdSASLCRAMMD5.Create;
    CRAMMD5.UserPassProvider := TIdUserPassProvider.Create(CRAMMD5);
    CRAMMD5.UserPassProvider.Password := 'mypassword';
    CRAMMD5.UserPassProvider.Username := 'myusername';
    SMTP.SASLMechanisms.Add.SASL := CRAMMD5;

    SMTP.AuthType := atSASL;
    SMTP.Connect;

    if SMTP.Authenticate then
      begin
        SMTP.Send(IdMsg);
        ShowMessage('Email Sent');
      end;

  finally
    IdMsg.Free;
  end;
end;

Replies