Email Fundamentals

The built-in email feature provides numerous ways to export and send a report via email in a single step.  Below is a description of how this can be done.

Send an email from the Preview Window:

  1. Set the TppReport.EmailSettings.Enabled property to True.
  2. Set up the rest of the email settings inlcuding whether you would like to use the built-in email dialog (ShowEmailDialog) or preview the email in your default client (PreviewInEmailClient).
  3. Click the “email” button on the top toolbar of the Preview window to export and send the report being previewed.

Send an email in code from the Report:

  1. Set the TppReport.EmailSettings properties to your specifications.
  2. Call the Report.SendMail routine to automatically export the report and send the email.

Export and Send multiple reports at once:

  1. Create a TppEmail object
  2. Use the TppEmail.AddReport() routine to add as many reports to the emails as you need.  Note that the first report added will provide the email settings for all reports exported and sent.
  3. Call the TppEmail.Send routine to export and send all the reports added in one email.

 

Download: EmailExample.zip

Sample Delphi code:

Send an email from the preview window:

procedure TEmailFrm.btnPreviewClick(Sender: TObject);
begin
  //Register MAPI plugin...
  TppSMTPPlugIn.RegisterClass(TppSMTPMapi);

  ppReport1.EmailSettings.ShowEmailDialog := False;
  ppReport1.EmailSettings.PreviewInEmailClient := True;

  ppReport1.EmailSettings.Enabled := True;
  ppReport1.Print;

end;

Send an email from the report:

procedure TEmailFrm.btnMAPIClick(Sender: TObject);
begin
  //Register MAPI plugin...
  TppSMTPPlugIn.RegisterClass(TppSMTPMapi);

  ppReport1.EmailSettings.ShowEmailDialog := False;
  ppReport1.EmailSettings.PreviewInEmailClient := True;

  ppReport1.EmailSettings.Body.Text := cMapiMail;

  ppReport1.SendMail;

end;

Send multiple emails using the TppEmail object:

procedure TEmailFrm.btnSendEmail(Sender: TObject);
var
  lEmail: TppEmail;
begin

  //Register MAPI plugin...
  TppSMTPPlugIn.RegisterClass(TppSMTPMapi);

  lEmail := TppEmail.Create;

  try
    ppReport1.EmailSettings.ShowEmailDialog := False;
    ppReport1.EmailSettings.PreviewInEmailClient := True;

    ppReport1.EmailSettings.Body.Text := cMapiMail;

    //Add reports
    lEmail.AddReport(ppReport1);
    lEmail.AddReport(ppReport2);
    lEmail.AddReport(ppReport3);

    lEmail.Send;

  finally
    lEmail.Free;
  end;

end;