AutoSend problem

delphi package - automated exception handling
Post Reply
caetanofe
Posts: 5
Joined: Thu Feb 12, 2015 5:56 pm

AutoSend problem

Post by caetanofe »

I'm using the latest madExcept 4.0.11 in Delphi 2007.

In ExceptionHandler I set the "Settings.AutoSend := True" but the email is not send.

When I use the below function in ExceptionHandler works fine:

SendSmtpMail(MESettings.MailAddr, MESettings.MailAddr, MESettings.MailSubject, MESettings.MailBody),

Need other settings for use AutoSend, what I do wrong?
Attachments
madExcept.png
madExcept.png (69.39 KiB) Viewed 9246 times
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: AutoSend problem

Post by madshi »

Sorry for the late reply. Can you please show me your exact exception handler code? And also the RegisterExceptionHandler line. Thanks.
caetanofe
Posts: 5
Joined: Thu Feb 12, 2015 5:56 pm

Re: AutoSend problem

Post by caetanofe »

RegisterExceptionHandler line

Code: Select all

RegisterExceptionHandler(OurExceptionHandler, stDontSync);
Exception handler code

Code: Select all

procedure TExceptionsManager.OurExceptionHandler(const exceptIntf : IMEException;
  var handled: boolean);
var
  vNumber: Integer;
  vSendMail: Boolean;
begin    
  if IsDBConnectionError(exceptIntf) then
  begin
    // Deixar para o próximo handler.
    Exit;
  end;

  // Sistemas.Logs.Add('DEB', 1, 'ApplicationException: ' + E.Message);
  if (exceptIntf.Source = esAntiFreezeCheck) or
    ((exceptIntf.ExceptObject <> nil) and
     (exceptIntf.ExceptObject.ClassType = EOutOfMemory) or
     (exceptIntf.ExceptObject.ClassType = EOutOfResources)) then
  begin
    exceptIntf.CanContinue := False;
    exceptIntf.AutoRestart := 1; // at once
    exceptIntf.AutoDelay := 10; // in 10 seconds
  end;

  exceptIntf.BeginUpdate;
  try
    exceptIntf.BugReportSections.Add('detalhes',
      GetDetalhesReport);

    exceptIntf.BugReportSections.Add('conexoes',
      GetServidoresReport);
  finally
    exceptIntf.EndUpdate;
  end;

  vSendMail := False;
  if (not fParams.IsDebuggerPresent) and (Sistemas.RelatorioAutomatico) then
  begin
    vNumber := StrToIntDef(exceptIntf.BugReportHeader['exception number'], -1);
    vSendMail := (vNumber > 0) and (vNumber <= 3);
  end;

  // vSendMail := True; // just for test, try set always true in AutoSend, but didn't work;
  MESettings.AutoSendPrgrBox := vSendMail;
  MESettings.AutoSend := vSendMail;

  if vSendMail then
  begin
    MESettings.MailSubject := 'MadExcept report ' + fParams.AppName + ' ' + fParams.AppVersao;
    MESettings.MailBody := exceptIntf.BugReport;

  // When we use code below for send the email works fine
  //    if SendSmtpMail(MESettings.MailAddr, MESettings.MailAddr, MESettings.MailSubject, MESettings.MailBody) then
  //      DebugMediador.Debugar(Self, 'Mail sent successfuly!')
  //    else
  //      DebugMediador.Debugar(Self, 'Error when sending mail!');
  end;
end;
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: AutoSend problem

Post by madshi »

You're using "MESettings.AutoSend := vSendMail". That won't work because that changes the global settings. The current global settings are copied as the starting point for each exception in the moment when exception handling starts. When your exception handler is called, the MESettings were already copied to the IMEException interface. So you need to change "exceptIntf.AutoSend := vSendMail". I'm not totally sure whether this is the full reason for the failure, though. There's one more potential problem: I'm not sure exactly at which point in time madExcept starts the auto sending. It's possible that your exception handler runs "too late", meaning that it's run after the auto sending should have already begun.

Anyway, please first try changing "MESettings" to "exceptIntf". Maybe that already fixes the problem. If not, we'll go from there...
caetanofe
Posts: 5
Joined: Thu Feb 12, 2015 5:56 pm

Re: AutoSend problem

Post by caetanofe »

We tried exceptIntf but didn't work, stop work when try "connecting to server".

In other test we use the button "Mail bug report" to send but has the same problem, please see the image attached. "Sorry, sending the mail didn't work"

Just works with the command "SendSmtpMail".
Attachments
madExcept_Error.png
madExcept_Error.png (30.86 KiB) Viewed 9215 times
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: AutoSend problem

Post by madshi »

The first question to clarify is whether any of this has to do with changing the settings at runtime, or whether SMTP mailing generally doesn't work for you (unless you call SendSmtpMail manually). Can you please clarify that?

One thing you could try is setting "exceptIntf.MailFrom := exceptIntf.MailAddr". That might move madExcept's automated SMTP mailing nearer to your manual SendSmtpMail() call.
caetanofe
Posts: 5
Joined: Thu Feb 12, 2015 5:56 pm

Re: AutoSend problem

Post by caetanofe »

Thats correct, SMTP mailing doesn't work unless we call SendSmtpMail manually.

In ExceptionHandler we use your suggestion, but didn't work to:

Code: Select all

  
  exceptIntf.MailAddr := MESettings.MailAddr;
  exceptIntf.MailFrom := MESettings.MailAddr;
  exceptIntf.MailSubject := MESettings.MailSubject;
  exceptIntf.MailBody := MESettings.MailBody;
  exceptIntf.AutoSendPrgrBox := True;
  exceptIntf.AutoSend := True;
Our other test is using a interface from MadExcept
In Project > MadExcept settings > Exception Box settings > Check "Send bug report"
When have an error we try send email using the button "Mail bug Report " with "Send Assistance", but didn't work: "Error: Sorry, sending the mail didn't work".
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: AutoSend problem

Post by madshi »

Strange thing. Is that SMTP account available via internet? If so, could you create a small test project with the SMTP account with password setup correctly in madExcept, so I could test it on my development PC? Of course I'd give you my word that I'd only use the SMTP account for testing this problem and afterwards delete/forget the password. madshi (at) gmail (dot) com.
caetanofe
Posts: 5
Joined: Thu Feb 12, 2015 5:56 pm

Re: AutoSend problem

Post by caetanofe »

Sorry for the late reply.
I tested in a new project and works fine using "exceptIntf". Then I updated the version and installed the new version in the same folder of the old version, maybe some file cause the error, i don't know exactly. Now I installed version 4 in a new folder and madExcept can send email.

Thanks a lot for all your help!
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: AutoSend problem

Post by madshi »

Not sure what the problem was, but I'm glad to hear it's gone now.
Post Reply