eDocEngine VCL
Create documents and reports in 18 formats
Compatibility
Delphi C++Builder

Create and Email PDF Reports with eDocEngine

Learn how to automate emailing of generated documents when exporting reports or creating documents from scratch using eDocEngine. We’ll use the built-in email adapter for Indy to perform this task.

eDocEngine VCL provides document creation components for several formats. We call these components document creation engines. The document creation engines also provide the option to email the created document.

Using Indy and eDocEngine you can email the document while exporting reports to specific format as well as when creating documents from scratch.

To make the process of emailing easy, eDocEngine implements an adapter framework for the email providers. You need to install the email adapter component based on your email provider class (Indy or other library), place that adapter component on the form, along with the Engine components, and set the EmailAdapter property of the Engine to the placed Email Adapter.

Your eDocEngine installation folder has the Pascal source for an Indy-based e-mail adapter component. You will find it at: [eDocEngine Installation Folder]\Source\EmailAdapters\IndyAdapter (There are separate projects for different IDE version. For example, use the project suffixed with "D14" for Delphi 2010.) If you are using some other emailing component, then you need to build your own e-mail adapter component, keeping the IndyAdapter project as your model. After compilation and installation of the e-mail adapter component, you will find the adapter listed in the "eDocEngine Additional" tab of the Tool Palette. You can also instantiate an object of the adapter in code. If you do that, you will have to assign the created instance to the EmailAdapter property of the engine that you are using to generate the documents.

The Engine components have the property EmailAfterCreate. The output document can be e-mailed to specified recipients if this property is set to True. The e-mail settings including the e-mail recipients need to be specified in the EmailSettings property. To get notified when the engine begins sending messages, set an event handler for the OnEmail event. To recover from e-mail errors, set an event handler for the OnEmailError event.

Scenario 1: Email PDF document created from scratch.

Add the following components to a form:
  1. TgtIndyAdapter
  2. TgtPDFEngine
  3. TButton


In the Button Click event handler, write the following code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  gtPDFEngine1.FileName := 'Demo_TgtEMailSettings.pdf';
  // Set the enail Adapter to Indy
  gtPDFEngine1.EmailAdapter := gtIndyAdapter1;
  gtPDFEngine1.Preferences.EmailAfterCreate := True;
  // Specify e-mail settings
  gtPDFEngine1.EMailSettings.Host := 'smtp.googlemail.com';
  gtPDFEngine1.EMailSettings.Port := 465;
  gtPDFEngine1.EMailSettings.UserID := 'me@gnostice.com';
  gtPDFEngine1.EMailSettings.Password := 'password';
  gtPDFEngine1.EMailSettings.Subject := 'Season''s greeting';
  gtPDFEngine1.EMailSettings.Body.Add('Hi ' + Chr(10) + Chr(10) +
    'Please see attachment.');
  gtPDFEngine1.EMailSettings.Date := now();
  gtPDFEngine1.EMailSettings.FromName := 'Mamatha';
  gtPDFEngine1.EMailSettings.FromAddress := 'me@gnostice.com';
  // Specify recipients
  gtPDFEngine1.EMailSettings.RecipientList.Add('janedoe@example.com');
  gtPDFEngine1.EMailSettings.RecipientList.Add('jeandoe@example.com');

  // Create the document
  gtPDFEngine1.BeginDoc;
  gtPDFEngine1.Textout(3, 3, 'This document needs to be mailed out.');
  gtPDFEngine1.EndDoc;
end;

procedure TForm1.gtPDFEngine1Email(Sender: TgtCustomDocumentEngine;
  EMailSettings: TgtEmailSettings; var Continue, CancelEMail: Boolean);
begin
  ShowMessage('Mailing ....');
end;

procedure TForm1.gtPDFEngine1EmailError(Sender: TgtCustomDocumentEngine;
  const ErrMsg: string);
begin
  ShowMessage('I could not mail the output document because of this error: "' +
    ErrMsg + '"');
end;

Scenario 2: Export a FastReport report to PDF and Email it automatically.


Add the following components to a form:
  1. TgtIndyAdapter
  2. TgtPDFEngine
  3. TgtFRExportInterface
  4. TButton



In the Button Click event handler, write the following code:
   procedure TForm1.Button1Click(Sender: TObject);
begin
  // Load report
  frxReport1.PreviewPages.LoadFromFile('FastReport.fp3');
  // Set output file name for the PDF engine
  gtPDFEngine1.FileName := 'Test1';
  // Set the enail Adapter to Indy
  gtPDFEngine1.EmailAdapter := gtIndyAdapter1;
  // Set email settings
  gtPDFEngine1.Preferences.EmailAfterCreate := True;
  // Specify e-mail settings

  gtPDFEngine1.EMailSettings.Host := 'smtp.googlemail.com';
  gtPDFEngine1.EMailSettings.Port := 465;
  gtPDFEngine1.EMailSettings.UserID := 'me@gnostice.com';
  gtPDFEngine1.EMailSettings.Password := 'password';
  gtPDFEngine1.EMailSettings.Subject := 'FastReport report to PDF';
  gtPDFEngine1.EMailSettings.Body.Add('Hi ' + Chr(10) + Chr(10) +
    'Please see attached report.');
  gtPDFEngine1.EMailSettings.Date := now();
  gtPDFEngine1.EMailSettings.FromName := 'Mamatha';
  gtPDFEngine1.EMailSettings.FromAddress := 'me@gnostice.com';
  // Specify recipients
  gtPDFEngine1.EMailSettings.RecipientList.Add('girish@gnostice.com ');

  // Connect report export interface to PDF engine
  gtFRExportInterface1.Engine := gtPDFEngine1;
  // Export report to PDF
  gtFRExportInterface1.RenderDocument(frxReport1, True, False);
end;

procedure TForm1.gtPDFEngine1EmailSuccess(Sender: TObject);
begin
  Showmessage('Email sent..');
end;

---o0O0o---

Our .NET Developer Tools
XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2017 Gnostice Information Technologies Private Limited. All rights reserved.