Email PDF attachments from Pick Emailing from D3 with attachments

How To Email Invoices From D3 On Linux, AIX Or Windows

The Real Question Is:

How do I send out an email from D3 to a customer with a PDF invoice attached?

The Basic Steps Are:

  1. Collect the data with a BASIC program in your D3 database.
  2. Have a PDF template with line drawing commands stored as a D3 record.
  3. Merge the data to the end of the template and saving this as a D3 record.
  4. Build the email message letting the customer know there is an invoice attached.
  5. Call SENDREC from Pathfinders Email Gateway product to render the template into a PDF, attach it to the email message and send it out onto the Internet.

1. Collect The Data

I will assume you know how to collect your invoice data. You will need a BASIC programmer if you are not one yourself. I do provide this custom programming service, by the way...

2. PDF Template

Create a D3 file to store records that are really PDF templates. Some people call these forms. Each one will have Postscript commands and header and footer data (remittance address, phone, etc.). This is where you tell the laser printer to draw lines, change fonts and colors, insert graphics in EPS format, etc.

Here is a sample template you may use: Sample Invoice Template

This template uses this logo graphic file: Sample EPS Logo

The logo should be placed in the /tmp directory in your Linux or AIX system. If you are on Windows you will have to edit the template and change the path on the first line.

Here is my PDF Template Guide. Read if you want to learn how to design these. We are using the enscript command and Ghostscript. Both are available for Windows, Linux and AIX.

3. Merge The Data Into The Template

Merging the data into the template is just a matter of placing this data at the bottom. So, your D3 BASIC program will read the record for the template, append the collected data and write it out as a new record to be attached later to your email.

This is possible because the template draws all the lines on the page and then specifies a courier fixed width font for your data. So, your data is overlayed onto the page. This is like a two pass system to build the page. Just use proper spacing to get the columns to line up with the predrawn lines.

This would all still work without a fancy template. You can have an all Courier font invoice if you like.

Here is an example of invoice data to merge with the above template: Sample Data To Merge

4. Build The Email Message

You have two choices when building your email message to pass to our SENDREC program.

First choice: Easy

The easy way is to build a very simple email message as a D3 record like this. Then let SENDREC create the two MIME sections of the email automatically. One for the readable area and one for the attachment area.

Second choice: Harder

The harder way is to create a more complex email message that has three MIME sections. A text section, an HTML section and an attachment section. This way the email message allows email reader programs (that can handle HTML) the choice to show the HTML section and hide the text section.

You will have to create the 3 MIME sections yourself and tell SENDREC not to do it with (M option.

Here is a sample of what the email message would look like. Three section message

Notice that the 3rd section starts with !!. This tells SENDREC where to insert the pdf file after it renders it into PDF format.

5. Call SENDREC to send it all out

SENDREC is part of Pathfinders Software package called The Email Gateway. Basically, this program converts the attachment to pdf and then encodes it for email tranmission. Finally, SENDREC uses SMTP protocol to send it to your mail server. If you use SMTP authentication, SENDREC can login first.

Here is a sample program that does it the hard way. SEND.INVOICE

And here's what the invoice rendered into as a real PDF document: Invoice H46160

That's it! I hope this article was helpful.