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:
- Define required variables
- Create a custom email message
- Configure eDIRECT to use your SMTP server
- 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.
- 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
- Right click the first digit of the invoice number > Add Variable.
- Name the variable InvoiceNo, click Copy original data to output, and click OK.
- 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:
- Right click the form > Add variable > By position. (The position is unimportant because you do not print it on the form.)
- Name the variable Subject and click OK.
- Right click the variable > Add function > Set value.
- In the Constant field type text to come before the invoice number in the email subject, for example, Your Shoe Co. invoice #. Click OK.
- Right click the Subject variable > Add function > Concatenate.
- Click Variable and select InvoiceNo. Click OK.
- 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
- At the bottom of the Project window, click the eDIRECT or eDIRECT PLUS tab.
- Right click the eDIRECT icon > Add Output > E-Mail.
- Right click the E-Mail icon > Add body.
- 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.
- 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
- Right click the E-Mail icon > Add provider > JavaMail.
- In the SMTP Host field, enter the IP address or hostname and domain of your SMTP server.
- In the From field, enter the email address you want the message to show as the sender.
- In the To field, click Variable, and select the email address variable that you already created.
- In the Subject field, enter a subject.
- Click the SMTP Options tab.
- 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
- Right click the E-Mail icon > Add attachment > Generated content.
- In the Format field, select PDF and then click OK.
- 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).