SergioFeitoza Posted March 20, 2021 Share Posted March 20, 2021 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 Quote Link to comment Share on other sites More sharing options...
irigsoft Posted March 20, 2021 Share Posted March 20, 2021 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. Quote Link to comment Share on other sites More sharing options...
SergioFeitoza Posted March 20, 2021 Author Share Posted March 20, 2021 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 ? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted March 20, 2021 Share Posted March 20, 2021 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 Quote Link to comment Share on other sites More sharing options...
SergioFeitoza Posted March 20, 2021 Author Share Posted March 20, 2021 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 Quote Link to comment Share on other sites More sharing options...
irigsoft Posted March 20, 2021 Share Posted March 20, 2021 4 minutes ago, SergioFeitoza said: Thank you IRISOFT I will try to do something in this direction 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 Quote Link to comment Share on other sites More sharing options...
SergioFeitoza Posted March 20, 2021 Author Share Posted March 20, 2021 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; Quote Link to comment Share on other sites More sharing options...
SergioFeitoza Posted March 20, 2021 Author Share Posted March 20, 2021 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 Quote Link to comment Share on other sites More sharing options...
irigsoft Posted March 20, 2021 Share Posted March 20, 2021 I can't help on this point, sorry. If You make Your solution, if have too many connections, and too many errors, then i think production of the server will slowdown I think it ' s better sollution to send log files one or more time on day Quote Link to comment Share on other sites More sharing options...
SergioFeitoza Posted March 20, 2021 Author Share Posted March 20, 2021 4 minutes ago, irigsoft said: I can't help on this point, sorry Thanks You gave me a great help and now I can do something understanding better how the log files are generated Regards Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.