Re: IDSmtp

Giganews Newsgroups
Subject: Re: IDSmtp
Posted by:  Remy Lebeau (Indy Team) (no.spam@no.spam.com)
Date: Mon, 14 Aug 2006

"Michael Johnson" <architeuthis6…@yahoo.com> wrote in message
news:3A7AFC46E403E340architeuthis6…@yahoo.com...

> Bill, you have a try...finally with no 'except' clause. You are
> probably failing with an exception

Given Bill's description, that is the only way both halves of the 'if
Connected' block would not be executed.

> since you have no 'except' the finally clause catches the exception
> and supresses it.

The 'finally' block does not suppress exceptions.  It ensures that the block
is always run even if an exception is thrown, but the exception continues up
the call stack after the 'finally' block exits.

> I believe you want to do something like this:

Use this instead:

    MyMail := TIdSmtp.Create(Self);
    try
        try
            with MyMail do
            begin
                AuthenticationType := atNone;
                Host := SMTPAddress;
                Connect(10);
                try
                    Send(MyMessage);
                finally
                    Disconnect;
                end;
            end;
            ShowMessage('Email has been sent.');
        finally
            MyMail.Free;
        end;
    except
        on E: Exception do
        begin
            Beep;
            ShowMessage('Error - ' + E.Message);
        end;
    end;

Gambit

Replies

In response to

Re: IDSmtp posted by Michael Johnson on Mon, 14 Aug 2006