Jump to content

Token triggered by an (bug) error message


SergioFeitoza

Recommended Posts


Hi. I am putting “in the air”, next few days – as free - a kind of calculation service prepared with Unigui. This forum helpd me alot to develop it. 

After registering,  the user do the Login and may use the Service.  I will post a link here next days to access it. 

 The VCL version is working  10+ years and bugs are rare. For this Web version, certainly  many bugs will come as the number of users increase.
MY QUESTION IS:  I would like to implement something, as simple as possible, to automatically return me, an e-mail  message if (hen a user is using it) an error / bug occurs that does not allow to continue using it. Something like a token  triggered by the error.

Can anyone suggest me a small code that I can use as starting point ?

I thank you in advance

Link to comment
Share on other sites

1 hour ago, SergioFeitoza said:


Hi. I am putting “in the air”, next few days – as free - a kind of calculation service prepared with Unigui. This forum helpd me alot to develop it. 

After registering,  the user do the Login and may use the Service.  I will post a link here next days to access it. 

 The VCL version is working  10+ years and bugs are rare. For this Web version, certainly  many bugs will come as the number of users increase.
MY QUESTION IS:  I would like to implement something, as simple as possible, to automatically return me, an e-mail  message if (hen a user is using it) an error / bug occurs that does not allow to continue using it. Something like a token  triggered by the error.

Can anyone suggest me a small code that I can use as starting point ?

I thank you in advance

I try to help with part of main code, but You must work on it;

 

var
AttachedFile  : TIdAttachmentFile;  //attachment
mCount,
I,J,
iCodePage     : Integer;
SMTPClient    : TSMTPSend;
Msg           : TMimeMess;
MimePart      : TMimePart;

begin

        + '#Mail=YouMail
        + '#Host=YouMailHost
        + '#Port=587' //port to connect
        + '#User=YouMail
        + '#Pass=YouPassToMail
        + '#UseSSL=False'   //False
        + '#Recepient=' + recepientMail
        + '#SubjectText=YourSubjectofMail
        + '#MessageText=YourErrorMessage

//use SMTP to send message

     SMTPClient := TSMTPSend.Create;
      SMTPClient.TargetHost := YouHost
      SMTPClient.TargetPort := YouMailPort
      SMTPClient.UserName := MailUserName
      SMTPClient.Password := MailPass
      //SMTPClient.AutoTLS := True;
      //if sParameters.Values ['UseSSL'] <> '' then
      //    SMTPClient.AutoTLS := StrToBool (sParameters.Values ['UseSSL']);
      //if sParameters.Values ['FullSSL'] <> '' then
      //    SMTPClient.FullSSL := StrToBool (sParameters.Values ['FullSSL']);

      //if SMTPClient.Login then begin
        // for mCount := 0 to EmailsList.Count - 1 do begin
           Msg := TMimeMess.Create;
           TRY
              Msg.Header.Date := Now;
              Msg.Header.Priority := mp_Normal;
              //Msg.Header.CharsetCode := ISO_8859_1;
              Msg.Header.From := MailYouser
              Msg.Header.ToList.Add (Recepient);
              Msg.Header.Subject := SubjectofMail
              Msg.Header.XMailer {CustomHeaders.Values ['X-mailer']} := 'Sender Information'; //trade mark or something

              //connect to host
              if (SMTPClient.Login)
              and (SMTPClient.AuthDone) then begin
                  if SMTPClient.MailFrom (GetEmailAddr (Msg.Header.From), Length(Msg.Lines.Text)) then begin
                      if not SMTPClient.MailTo (RecepientMail) then 
                            Result := 'Error' + #13#10 + RecepientMail;

                        //If No error message, send message
                        if Result = '' then  SMTPClient.MailData (Msg.Lines);
                 end; 
              end; //if (SMTPClient.Login)

           FINALLY
              Msg.Free;
              //MimePart.Free;
              AttFileList.Clear;
              AttFileList.Free;
           END;

      //end; //for mCount
      SMTPClient.Logout;

   //end;//if SMTPClient.Login then begin
end;

 

I wish You good luck.

Link to comment
Share on other sites

3 minutes ago, irigsoft said:

I try to help with part of main code, but You must work on it;

 

var
AttachedFile  : TIdAttachmentFile;  //attachment
mCount,
I,J,
iCodePage     : Integer;
SMTPClient    : TSMTPSend;
Msg           : TMimeMess;
MimePart      : TMimePart;

begin

        + '#Mail=YouMail
        + '#Host=YouMailHost
        + '#Port=587' //port to connect
        + '#User=YouMail
        + '#Pass=YouPassToMail
        + '#UseSSL=False'   //False
        + '#Recepient=' + recepientMail
        + '#SubjectText=YourSubjectofMail
        + '#MessageText=YourErrorMessage

//use SMTP to send message

     SMTPClient := TSMTPSend.Create;
      SMTPClient.TargetHost := YouHost
      SMTPClient.TargetPort := YouMailPort
      SMTPClient.UserName := MailUserName
      SMTPClient.Password := MailPass
      //SMTPClient.AutoTLS := True;
      //if sParameters.Values ['UseSSL'] <> '' then
      //    SMTPClient.AutoTLS := StrToBool (sParameters.Values ['UseSSL']);
      //if sParameters.Values ['FullSSL'] <> '' then
      //    SMTPClient.FullSSL := StrToBool (sParameters.Values ['FullSSL']);

      //if SMTPClient.Login then begin
        // for mCount := 0 to EmailsList.Count - 1 do begin
           Msg := TMimeMess.Create;
           TRY
              Msg.Header.Date := Now;
              Msg.Header.Priority := mp_Normal;
              //Msg.Header.CharsetCode := ISO_8859_1;
              Msg.Header.From := MailYouser
              Msg.Header.ToList.Add (Recepient);
              Msg.Header.Subject := SubjectofMail
              Msg.Header.XMailer {CustomHeaders.Values ['X-mailer']} := 'Sender Information'; //trade mark or something

              //connect to host
              if (SMTPClient.Login)
              and (SMTPClient.AuthDone) then begin
                  if SMTPClient.MailFrom (GetEmailAddr (Msg.Header.From), Length(Msg.Lines.Text)) then begin
                      if not SMTPClient.MailTo (RecepientMail) then 
                            Result := 'Error' + #13#10 + RecepientMail;

                        //If No error message, send message
                        if Result = '' then  SMTPClient.MailData (Msg.Lines);
                 end; 
              end; //if (SMTPClient.Login)

           FINALLY
              Msg.Free;
              //MimePart.Free;
              AttFileList.Clear;
              AttFileList.Free;
           END;

      //end; //for mCount
      SMTPClient.Logout;

   //end;//if SMTPClient.Login then begin
end;

 

I wish You good luck.

Thanks IRIGSOFT

This will be useful but there is something that I can not understand and is ny main doubt

Where is the "error detection" which would triger the text you wrote ?

Link to comment
Share on other sites

18 minutes ago, SergioFeitoza said:

Thanks IRIGSOFT

This will be useful but there is something that I can not understand and is ny main doubt

Where is the "error detection" which would triger the text you wrote ?

There is only send mail, no get error message.

You can use this to log messages on server local file:

UniServerModule.Logger.AddLog ('SysLog',FormatDateTime ('dd.MM.yyyy HH:mm:ss',Now,UniServerModule.MySettings) + ' : ' + SomeMessage                            ,'HtmlLog');

 

So every moment on Try Except You can use that to save error message
 

Link to comment
Share on other sites

34 minutes ago, irigsoft said:

There is only send mail, no get error message.

You can use this to log messages on server local file:

UniServerModule.Logger.AddLog ('SysLog',FormatDateTime ('dd.MM.yyyy HH:mm:ss',Now,UniServerModule.MySettings) + ' : ' + SomeMessage                            ,'HtmlLog');

 

So every moment on Try Except You can use that to save error message
 

Thank you IRISOFT  I will try to do something in this direction

Link to comment
Share on other sites

4 minutes ago, irigsoft said:

If I can propose to You , make function that report to You every day log files.

Just on 0:00 send mail with all log files generated on Server

I think I understood your idea. I will try to do understand better

I was imagining something more or less like below but need to know the right point to insert it ( In servermodule ??? )

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnException := AppException;
end;

procedure TForm1.AppException(Sender: TObject; E: Exception);
begin
  Application.ShowException(E);
  SendTheEnailToMe;                   /// <<<<<<<
//  Application.Terminate;
end; 

// procedure TForm1.Button1Click(Sender: TObject);
// begin
//   raise EPasswordInvalid.Create('Incorrect password entered');
// end;

 

Link to comment
Share on other sites

12 minutes ago, SergioFeitoza said:

I think I understood your idea. I will try to do understand better

I was imagining something more or less like below but need to know the right point to insert it ( In servermodule ??? )


procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnException := AppException;
end;

procedure TForm1.AppException(Sender: TObject; E: Exception);
begin
  Application.ShowException(E);
  SendTheEnailToMe;                   /// <<<<<<<
//  Application.Terminate;
end; 

// procedure TForm1.Button1Click(Sender: TObject);
// begin
//   raise EPasswordInvalid.Create('Incorrect password entered');
// end;

 

Maybe something including the Logger Property 

 TUniGUIServerModule.Logger Property

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...