Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Feb : Re: Internal Application Error

www.cryer.info
Managed Newsgroup Archive

Re: Internal Application Error

Subject:Re: Internal Application Error
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Tue, 5 Feb 2008 19:28:30

"mark horrocks" <markhorrocks@yahoo.com> wrote in message
news:47a92257@newsgroups.borland.com...

> When it sends back a blank screen, it is
> <html><head></head><body><p></body></html> with no
> Msg inserted. I guess E.message is not being inserted here

E.Message would have to be a blank value, yes.  You could substitute in the
exception class type in that scenerio:

    except
        on E: Exception do
        begin
            Msg := E.Message;
            if Msg = '' then Msg := E.ClassName;
        end;
    end;

> under this circumstance the email is always sent

Given the code I showed earlier, the only possibility would be if
Disconnect() were raising an exception after successfully sending a QUIT
command to the server.  Otherwise, you should be seeing 'Email(s) sent
successfully!' instead.

Any chance multiple clients are accessing your TIdSMTP and TIdMessage
instances at the same time?  What happens if you try dynamically allocating
them inside of WebModule1waSendMailAction() each time?

    procedure TWebModule1.WebModule1waSendMailAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    var
        SMTP: TIdSMTP;
        Email: TIdMessage;
        Msg: String;
    begin
        try
            SMTP := TIdSMTP.Create(nil);
            try
                SMTP.Host := 'mail.sportdata.com.au';
                SMTP.Port := 25; //smtp service usually runs on this port

                Email := TIdMessage.Create(nil);
                try
                    Email.From.Address :=
Request.ContentFields.Values['FromAddress'];
                    Email.Recipients.EMailAddresses :=
Request.ContentFields.Values['FromAddress'];
                    Email.BccList.EMailAddresses :=
Request.ContentFields.Values['EmailAddresses'];
                    Email.Subject :=
Request.ContentFields.Values['Subject'];
                    Email.ContentType := 'text/html';

                    Email.Body.Text := '<html><head></head><body>' + '<p>' +
                        Request.ContentFields.Values['AdditionalMessage'] +
                        Request.ContentFields.Values['BodyText'] +
                        '</body></html>';

                    SMTP.Connect;
                    try
                        SMTP.Send(Email);
                    finally
                        SMTP.Disconnect;
                    end;
                finally
                    Email.Free;
                end;
            finally
                SMTP.Free;
            end;
            Msg := 'Email(s) sent successfully!';
        except
            on E: Exception do
            begin
                Msg := E.Message;
                if Msg = '' then Msg := E.ClassName;
            end;
        end;

        Response.Content := '<html><head></head><body><p>' + Msg +
'</body></html>';
    end;


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive