www.gnostice.com 

Tutorial - e-Mailing Exported documents

Top  Previous  Next

 

This tutorial guides you to send documents created by eDocEngine by mail as an attachment. For mailing through eDocEngine, you need to have the e-mail components installed in Delphi/C++Builder platforms. eDocEngine supports two mailing components for Delphi/C++Builder. They are 'Indy' and 'FastNet'. The mailing component 'Indy' is provided by Delphi and 'FastNet' is a third party component.

 

This tutorial creates a PDF output and e-mails them using the functions provided by the eDocEngine. Using PDF engine component of the eDocEngine, create a PDF output. The PDF output is sent as e-mail attachment by using eDocEngine.

 

Follow the prerequisite before proceeding with the programming of eDocEngine for email support.

 

Prerequisite

 

1. Install the third party component to support e-Mail in Delphi. The email component 'Indy' comes with Delphi but if you are using 'FastNet' need to install them.

2. Configure eDocEngine's '.inc' file from the location: "<eDocEngine Install Dir>\Source\gtDocDefines.inc".

a. Open the file "<eDocEngine Install Dir>\Source\gtDocDefines.inc" in Delphi/C++Builder.

b. Search for the below mentioned code in the 'gtDocDefines.inc',

 

   

    {---- E-Mail using FastNet units}

    {.$DEFINE EMailWithFastNet}

    {---- E-Mail using Indy units}

    {.$DEFINE EMailWithIndy}

    {.$DEFINE Indy900Up}

   {.$DEFINE Indy1000Up}

 

The above provided code needs to be modified appropriately for e-mail support in eDocEngine. Configure them for 'Indy' or 'FastNet' components.

 

If you are using 'FastNet' to send mails, replace '{.$DEFINE EMailWithFastNet}' to '{$DEFINE EMailWithFastNet}' by removing the dot.

 

If using 'Indy' to send mails, replace

'{.$DEFINE EMailWithIndy}' to {$DEFINE EMailWithIndy} by removing the dot. Also for 'Indy' component, configure for version support. Suppose you have installed Indy with version higher than v9.0 and lower than v10.0,  you need to modify {.$DEFINE Indy900Up} to {$DEFINE Indy900Up} by removing the dot. If you use Indy v10.0 or above, you need to modify {.$DEFINE Indy1000Up} to {$DEFINE Indy1000Up} by removing the dot.

 

Note: Do not modify the '{.$DEFINE Indy900Up}' if you have installed Indy Version lower than 9.

 

3.Re-Compile eDocEngine. Refer to "Re-compiling eDocEngine".

 

Programming eDocEngine to send E-mails

Create an application by using the methods and properties for mailing using eDocEngine. Follow these steps mentioned below:

 

Step 1. Creating a new project

Step 2. Adding the eDocEngine component

Step 3. Adding the button to the form

Step 4. Setting the properties

Step 5. Executing the Program

Step 6. Viewing Output

 

 

Step 1. Creating a new project

 

To quickly create a new project, follow the steps mentioned below:

1.Start Delphi
2.Select File | New Application from the Delphi menu. This will create a new project and a blank form.

 

Step 2. Adding the eDocEngine component

 

In the component palette, click 'eDocEngine' tab to view all the eDocEngine components. Select the 'PDF engine' component and place it on the form.

 

Step 3. Adding the button to the form

 

Go to 'Standard' tab in the component palette and add a 'Button' to the form. Change the 'Button' caption to 'Send Mail' in the properties window.    

 

Step 4. Setting the properties

 

1.Select the 'PDF engine' component in the form window.
2.In the 'Object Inspector' window, select the 'Events' tab. Double click the drop down for 'OnEMail' event.

 

Note: 'OnEMail' event is visible in the object inspector only if you have followed the steps in prerequisites.

 

3.This will select the PDFEngine object for the event and 'gtPDFEngine1Email' is displayed in the drop down menu.
4.Respective event handling function is generated in the code window.

 

5.In the code window go to the Procedure 'gtPDFEngine1Email()'.

 

6.Set the following properties in the event's procedure,

 

Delphi

 

procedure TForm1.Button1Click(Sender: TObject);

begin

with gtPDFEngine1 do

begin

   FileName := 'EmailDemo';

   BeginDoc;

     TextOut(1,1,'This is a test for eMail Support');

   EndDoc;

end;

end;

procedure TForm1.gtPDFEngine1EMail(Sender: TgtCustomDocumentEngine;

EMailSettings: TgtEMailSettings; var Continue, CancelEmail: Boolean);

begin

with EMailSettings do

begin

   Host := 'mail.smtp.yourdomain.com'; { your mail server name }

   UserID := 'userid'; { your account id }

   Password := 'password';

   Body.Add('<put message text here>');

   FromAddress := 'userid@yourdomain.com';

   Subject := '<put message subject here>';

   { Multiple recipients can be provided in a single string

   separated by a semi-colon (;) or by calling the Add method

   again for each recipient }

   RecipientList.Add('someone@thierdomain.com');

   // CCList.Add('<Carbon Copy Addresses>');

   // BCCList.Add('<Blind Carbon Copy Addresses>');

end;

end;

7.Double click 'Send Mail' button to view the procedure. Copy the code mentioned below.

 

 

Delphi

 

with gtPDFEngine1 do

begin

FileName := 'Demo.pdf';

BeginDoc;

   TextOut(1,1,'This is eDocEngine Email Test');

EndDoc;

end;

 

8.Save the application

 

Step 5. Executing the Program

 

1.When you run the above application the form pop-up. Click on 'Send Mail' button.
2.This will pop-up the PDF Setup window. Activate the checkbox 'Email After Create'
3.Click on 'OK'
4.Mail will be sent to the email-ids mentioned in the Source code.

 

Step 6. Viewing Output

 

Check the mailbox for the e-mails and attached PDF file.