SMTP config at runtime not working....

delphi package - automated exception handling
Post Reply
dkeith
Posts: 10
Joined: Wed Aug 19, 2015 5:32 pm

SMTP config at runtime not working....

Post by dkeith »

I'm trying to send an email bug report by configuring settings at runtime and sending when the custom exception form closes. Here is how I setup up the ExceptIntf interface in code:

Code: Select all

    MailAddr := '<recipient>';
    SendInBackground := True;
    MailAsSmtpClient := True;
    SmtpServer := '<server name/IP (tried both)>';
    SmtpPort := <port>;
    SmtpAccount := '<username>';
    SmtpPassword := '<password>';
//    MailViaMailTo := True;
    MailFrom := 'madExcept@<myserver>';
    MailSubject := '<subject line>';
    ScreenShotAppOnly := True;
//    AttachBugReport := True;
//    BugReportSendAs := 'ExceptionReport.txt';
//    ScreenShotSendAs := 'ScreenShot.bmp';
No matter how I tweak the settings it fails to send every time. Yet my SMTP outbound settings match my smtp mail client settings which work perfectly.

I've blanked out all settings in the madExcept dialog in the IDE at design time. When I click the button to continue, which closes the exception form, the formclose event fires and calls this code:

Code: Select all

var
  i: Integer;
begin
  i := 0;
  while i < FExceptionIntf.BugReportSections.ItemCount do
  begin
     if (FExceptionIntf.BugReportSections.Items[i] = 'hardware') or
        (FExceptionIntf.BugReportSections.Items[i] = 'processes') or
        (FExceptionIntf.BugReportSections.Items[i] = 'disassembling') or
        (FExceptionIntf.BugReportSections.Items[i] = 'cpu registers') or
        (FExceptionIntf.BugReportSections.Items[i] = 'modules') or
        (FExceptionIntf.BugReportSections.Items[i] = 'stack dump') then
      FExceptionIntf.BugReportSections.Delete(i)
     else
      inc(i);
  end;
 // FExceptionIntf.MailBody := FExceptionIntf.BugReportSections.Items[0] + FExceptionIntf.BugReportSections.Items[1];
  FExceptionIntf.SendBugReport;
I'm testing with the latest non-commercial version.

Thanks.
Last edited by dkeith on Tue Aug 25, 2015 6:09 pm, edited 1 time in total.
dkeith
Posts: 10
Joined: Wed Aug 19, 2015 5:32 pm

Re: SMTP config at runtime not working....

Post by dkeith »

Ok, figured out that our email server was not allowing me to send with a manufactured (not real) email account. Once I specified my email account as both the sender and receiver along with my credentials, it successfully sent.

Question: If I use the SendBugReport method how do I attach a screen shot to the bug report?

Thanks.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: SMTP config at runtime not working....

Post by madshi »

Ideally you'd set up the screenshot stuff before an exception occurs, by using the madExcept IDE settings dialog, or by changing the MESettings() settings at runtime. If you are already in an exception handler and the exception is already in the process of being handled, it's almost too late. At that point calling exceptIntf.SendBugReport() will not include the screenshot, if the settings didn't originally say so. You can work around that, if you must, by using madExcept.SendBugReport() instead of exceptIntf.SendBugReport(). The function madExcept.SendBugReport has a few more parameters, and allows you to specify a screenshot, which you can then manually created by using madNVBitmap.pas.
dkeith
Posts: 10
Joined: Wed Aug 19, 2015 5:32 pm

Re: SMTP config at runtime not working....

Post by dkeith »

Ok set it up like this(project file):

Code: Select all

begin
  RegisterExceptionHandler(TWSExceptHandler.madExceptionHandler,stTrySyncCallOnSuccess,epCompleteReport);
  with MESettings do
  begin
    ScreenShotAppOnly := True;
    BugReportFile := 'Event.log';
    AppendBugReports := True;
    ScreenShotDepth := 32;
    Filter1ShowSetting := ssNothing;
    NoDupFreezes := True;
    SendInBackground := True;
    MailSubject := 'An Exception Occurred within program';
    MailAddr := '<dest email addr';
    MailAsSmtpClient := True;
    SmtpServer := '<smtp server address/name>';
    SmtpPort := <smtp server port>;
    MailFrom := '<source email addr>';
    SmtpAccount := '<smtp server account user name>';
    ScreenShotSendAs := 'ScreenShot.bmp';
    AttachBugReport := True;
    BugReportSendAs := 'ExceptionReport.txt';
    ShowStackDump := False;
    ListThreads := True;
    ShowCpuRegisters := False;
    ShowDisAsm := False;
    HideUglyItems := True;
    ShowRelativeLines := True;
    ShowRelativeAddrs := False;
  end;
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(Tform2, form2);
  Application.Run;
And in the custom exception form:

Code: Select all

procedure TExceptionForm.ConfigException;
begin
  with FExceptionIntf do
  begin
    SmtpPassword := '<smtp server user account password>';
    AppendScreenShot := True;
    CreateScreenShot := True;
  end;
end;
This gives me the screenshot before the exception dialog shows.

Thanks!
dkeith
Posts: 10
Joined: Wed Aug 19, 2015 5:32 pm

Re: SMTP config at runtime not working....

Post by dkeith »

Purchased two licenses. Thanks!
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: SMTP config at runtime not working....

Post by madshi »

Thank you... :D
Post Reply