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

email - OnSend event

edited August 2009 in General
Hello

Delphi 2009 - RBuilder 11.05

I am using the default MAPI client to send emails via RBuilder preview.

I need to determine when an email has been sent from an RBuilder preview.
If there was a SMTP.OnSend or SMTP.AfterSent event for the TppSMTPMapi unit
I could proceed in a mannor similar to the one I use the SMTP.OnEmailError
event to capture SMPT errors (see below). Does anyone have a suggestion?

procedure TRBReportRequestLetter.RegisterMapiClient;
begin
//Register MAPI plugin...
TppSMTPPlugIn.RegisterClass(TppSMTPMapi);
end;

procedure TRBReportRequestLetter.FormCreate(Sender: TObject);
begin
//The following registers the EmailErrorEvent procedure with the
ppReports OnEmailError event
with ppReport1 do
begin
TppEmail(ppReport1.Email).SMTP.OnEmailError := EmailErrorEvent;
end;
end;

procedure TRBReportRequestLetter.EmailErrorEvent(Sender: TObject;
aErrorText: String);
begin
// ShowMessage(aErrorText);

if aErrorText = 'User Abort' then
begin
MessageDlg('The email was not sent because the user aborted the
procedure.',
mtError, [mbOK], 0);
end;
end;


TIA

John

Comments

  • edited August 2009
    Hi John,

    The email feature does not currently have Before and After events however
    this is something that we will consider adding in the future.

    One option is to use the OnStatusChange event which is implemented similarly
    to the OnEmailError event. When the OnStatusChange event fires with a
    "Success" message, the email has been sent.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2009
    Nico

    I have implemented the OnStatusChange as you suggested and I can obtain a
    "Success" message which allows me to append a new record to the treatment
    notes database table.

    What I have not been able to do is obtain text from the body of the email
    which was entered after the email dialog was displayed to the user. See
    code below. Do you have a suggestion as to how I could obtain the user
    entered text so that I could post that text to the treatment note record?

    procedure TRBReportRequestLetter2.FormCreate(Sender: TObject);
    begin
    //The following registers the EmailErrorEvent procedure with the
    ppReports OnEmailError event
    with ppReport1 do
    begin
    TppEmail(ppReport1.Email).SMTP.OnStatusChange :=
    EmailStatusChangeEvent;
    end;
    end;

    procedure TRBReportRequestLetter2.EmailStatusChangeEvent(Sender: TObject);
    var
    tempEmailBodyText: String;
    tempMAPIComponent: TppSMTPMapi;
    tempMAPIStatus: String;
    I: Integer;
    begin
    tempMAPIComponent := Sender as TppSMTPMapi;
    tempMAPIStatus := tempMAPIComponent.Status;

    if tempMAPIStatus = 'Success' then
    begin
    tempRequestEmailSent := True;

    for I := 0 to ppReport1.EmailSettings.Body.Count - 1 do
    begin
    tempEmailBodyText := tempEmailBodyText +
    ppReport1.EmailSettings.Body.Strings[I];
    end;

    showmessage(tempEmailBodyText); // This does not display text entered into
    the body of the email by the user
    // after the email
    dialog is displayed.
    end;
    end;

    I appreciate your efforts in this matter and anticipate your reply

    John



  • edited August 2009
    Hi John,

    Since you are using MAPI, I assume you are letting your users create the
    email message using the email application (outlook) editor. Unfortunately
    once responsibility for the email has been passed on to the email client,
    there is no way to gather information from it other than an error or success
    message.

    One option would be to use the Indy or Synapse plugins rather than MAPI and
    the built-in email editor included with ReportBuilder. This would allow you
    to access the TppEmail.EmailSettings property before or after the report has
    been sent and log the user input.

    Another option would be to remove the ability to use the email client editor
    (PreviewInEmailClient) and require your users to enter the body of the email
    before sending.

    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2009
    Nico

    I understand.

    Thanks

    John


This discussion has been closed.