Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Emailing report not exposing all errors

edited June 2007 in General
Hi,
I came across this thread when trying to work out how to check on the
progress of emailing a report
http://delphi.newswhat.com/geoxml/forumhistorythread?groupname=digital-metaphors.public.reportbuilder.general&messageid=447fe7f3@dellsc1420.

I've just downloaded version 10.06 and notice that you have now made the
change to return expose some of the errors from the TppSMTPIndy class.
However, you're not exposing all of them. Here's the connect function in
that class. Debugging into this to find out why my emails aren't being sent
it's throwing an exception on the FSMTP.Connect, however as this is outside
of the try, except block it's being thrown up through TppSMTPIndy.SendMail,
TppEmail.ProcessAndSend until it gets to TppEmail.Send where it is caught
and excepts silently (so I can't even catch it higher up). Similarly with
TppSMTPMapi and it's connect and sendmail methods if it fails on the
MapiLogon.

In the thread referred to above Nico recommends changing the .pas file, so I
assume you don't mind that I've chagned mine. I've detailed below the
originals and my changes (other than what's shown below I had to add
SysUtils into ppSMTPIndy's uses clause for access to Exception. I thought
you might want to consider these changes, or something similar, in a future
release.
Cheers,
Richard.

ORIGINAL
function TppSMTPIndy.Connect: Boolean;
begin

if not FSMTP.Connected then
begin
FSMTP.Host := Host;

{$IFDEF Delphi7}
FSMTP.UserName := UserID;
{$ELSE}
FSMTP.UserId := UserID;
{$ENDIF}

FSMTP.Password := Password;
FSMTP.Connect;
end;

try
Result := FSMTP.Connected and FSMTP.Authenticate;
except
{$IFDEF Delphi7}
EmailError := FSMTP.LastCmdResult.Text.Text;
{$ELSE}
EmailError := FSMTP.CmdResult;
{$ENDIF}

Result := False;
end;

end; {function, Connect}

MINE
function TppSMTPIndy.Connect: Boolean;
begin

try
if not FSMTP.Connected then
begin
FSMTP.Host := Host;

{$IFDEF Delphi7}
FSMTP.UserName := UserID;
{$ELSE}
FSMTP.UserId := UserID;
{$ENDIF}

FSMTP.Password := Password;
FSMTP.Connect;
end;
except
on E : Exception do
begin
EmailError := 'SMTP connection failed';
EmailError := E.message;
Result := false;
Exit;
end;
end;

try
Result := FSMTP.Connected and FSMTP.Authenticate;
except
{$IFDEF Delphi7}
EmailError := FSMTP.LastCmdResult.Text.Text;
{$ELSE}
EmailError := FSMTP.CmdResult;
{$ENDIF}

Result := False;
end;

end; {function, Connect}

ORIGINAL
function TppSMTPMapi.Connect: Boolean;
var
lcLogon: Cardinal;
begin

lcLogon := MapiLogon(Application.Handle, PChar(UserID), PChar(Password),
MAPI_LOGON_UI or MAPI_NEW_SESSION, 0, @FSessionHandle);

Result := (lcLogon = SUCCESS_SUCCESS);

if Result then Status := 'Connected';

end; {function, Connect}

MINE
function TppSMTPMapi.Connect: Boolean;
var
lcLogon: Cardinal;
begin

try
lcLogon := MapiLogon(Application.Handle, PChar(UserID), PChar(Password),
MAPI_LOGON_UI or MAPI_NEW_SESSION, 0, @FSessionHandle);
except
on E : Exception do
begin
EmailError := 'MAPI connection failed';
EmailError := E.Message;
end;
end;

Result := (lcLogon = SUCCESS_SUCCESS);

if Result then Status := 'Connected';

end; {function, Connect}

Comments

  • edited June 2007
    Hi Richard,

    Thanks for the information. We are constantly trying to enhance each
    feature in ReportBuilder and this is a definite improvement. The nice thing
    about the plugin architecture is that it easily allows you the developer to
    create or alter each plugin to fit their needs. I'll have this added to the
    next release of ReportBuilder

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited June 2007
    In case it's of interest to anyone else who is having problems sending
    emails, the exception thrown by the connect (with the SMTPIndy, not the
    MAPI) was a socket error 10053 which is caused by antivirus software on the
    machine blocking connection to port 25.

    Richard.
  • edited June 2007
    Thanks Richard, good info.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.