Latest News

the latest news from our team

Send an email message with an attached PDF file

You can use eFORMz together with eDIRECT PLUS to send your invoices, estimates, purchase orders, and other documents by email.


  • eFORMz 10.6 or later.
  • An eFORMz project with two forms. One form is the email message, and the other form is a customer document, such as an invoice, which is made into the PDF that you attach to your email message.
  • SMTP server that you can use to send messages. You need the IP address or fully-qualified domain name, and logon credentials if the server requires them.
  • A data file with information required to create an invoice.

Starting with a project that creates a customer invoice, this example includes the following procedures:

  1. Define required variables
  2. Create a custom email message
  3. Configure eDIRECT to use your SMTP server
  4. Create and attach the invoice PDF file to the email message

Define required variables

Start with a variable on the form that uniquely identifies the document. This invoice project is uniquely identified by the invoice number, so create a variable, InvoiceNo, that takes its value from the invoice number on the form.

  1. If the invoice data is plain text or a spool file, find the invoice number on the form. If the invoice data is in XML, add the variables to the form
  2. Right click the first digit of the invoice number > Add Variable.
  3. Name the variable InvoiceNo, click Copy original data to output, and click OK.
  4. Verify the value in the Variables window. If the variable is picking up extra characters, delete the variable and drag your mouse across the invoice number, right click > Add Variable, and complete step 3.

You also must have an email address variable that contains customer email addresses. If the email address is on the invoice, you can follow the same procedure that you used for the invoice number. Another option is to do a database lookup, which is the topic of an upcoming post.

Define the following variables for your email message:

  1. Right click the form > Add variable > By position. (The position is unimportant because you do not print it on the form.)
  2. Name the variable Subject and click OK.
  3. Right click the variable > Add function > Set value.
  4. In the Constant field type text to come before the invoice number in the email subject, for example, Your Shoe Co. invoice #. Click OK.
  5. Right click the Subject variable > Add function > Concatenate.
  6. Click Variable and select InvoiceNo. Click OK.
  7. Repeat these steps creating a variable named Body to include the body text of your email message. You can break lines of a plain-text message with an escaped carriage feed character (\\r).

Create a custom email message

  1. At the bottom of the Project window, click the eDIRECT or eDIRECT PLUS tab.
  2. Right click the eDIRECT icon > Add Output > E-Mail.
  3. Right click the E-Mail icon > Add body.
  4. Right click the Body icon > Add content > Generated. Make sure that the format is set to Text and click OK. Generated content lets you include variables from the project in the message. You can add constant text if you have a standard message that is the same for all customers.
  5. Right click the Content icon > Add Forms and select the email body form that you created. Click OK.

Configure eDIRECT to use your SMTP server

  1. Right click the E-Mail icon > Add provider > JavaMail.
  2. In the SMTP Host field, enter the IP address or hostname and domain of your SMTP server.
  3. In the From field, enter the email address you want the message to show as the sender.
  4. In the To field, click Variable, and select the email address variable that you already created.
  5. In the Subject field, enter a subject.
  6. Click the SMTP Options tab.
  7. Most SMTP servers require outgoing messages to be authenticated. If yours requires authentication, enter a user ID and password in the fields. Click OK.

Create and attach the invoice PDF file to the email message

  1. Right click the E-Mail icon > Add attachment > Generated content.
  2. In the Format field, select PDF and then click OK.
  3. To attach the invoice, right click the Content icon > Add Form and select the invoice form that you created. Click OK.

Save your changes and test the results. You can test by clicking Run > Process with eDIRECT (or eDIRECT PLUS).

Leave a Reply

Your email address will not be published. Required fields are marked *