Submitting form data via email using JavaScript

This walkthrough demonstrates how to submit the information in a PDF form via email using JavaScript. The files used in this walkthrough can be downloaded here: SubmitByEmail.doc and SubmitByEmail.pdf. They have been tested with Adobe Reader 8 and Microsoft Outlook 2003.

An alternative way of emailing form data is to use Email Form Data action.

  1. Launch Microsoft Word. Add five text boxes by choosing Add Text Box on CenoPDF menu. Set the name of those text boxes to DestinationEmail, FirstName, LastName,Street and Comments as the following screen shot.

    PDF email text fields in Microsoft Word

  2. Choose Add Push Button on CenoPDF menu. In the Push Button Properties dialog box, click Options tab. Set the normal button text as Send Email.

    Properties of PDF push button to send email

  3. Click the Actions tab, the Mouse Up trigger and the Add button.

    Add a PDF action for the push button in Microsoft Word

  4. Choose Action Type as JavaScript. Input the following JavaScript, then click the OK button.

    var destEmailField = this.getField("DestinationEmail");

    var firstNameField = this.getField("FirstName");
    var lastNameField = this.getField("LastName");
    var streetField = this.getField("Street");
    var commentsField = this.getField("Comments");

    var emailBody =
    "First Name: " + firstNameField.valueAsString + "\n" +
    "Last Name: " + lastNameField.valueAsString + "\n" +
    "Street: " + streetField.valueAsString + "\n" +
    "Comments: " + commentsField.valueAsString;

    app.mailMsg(true, destEmailField.value, "", "", "Test Message", emailBody);

    Javascript to send email from PDF form

  5. Here is the button we just added.

    Layout of email sender PDF form

  6. Export the document to a PDF file. Open it in Adobe Reader. Fill all fields. Click the Send Email button.

    Open the PDF form in Adobe Reader and submit the form by email

  7. The email client, Microsoft Outlook in our example, pops up with the contents we just created from the PDF file.

    Launch email client, Microsoft Outlook, to submit the form

    Note: This step uses Messaging Application Programming Interface (MAPI) in your computer to open Microsoft Outlook. MAPI is a messaging architecture that allows clients (Adobe Reader) to interact with email program. In most cases, MAPI is set up automatically after an email program, such as Microsoft Outlook, is installed. In very rare cases, however, if your user's computer does not have MAPI or it is not configured correctly, it is always a good idea for you to provide alternative ways, such as fax, to send information back.

    Test MAPI: Go to Windows Explorer, right click on any file and choose Send To > Mail Recipient from the context menu. If your email client opens, your MAPI is OK. Otherwise, if your email client does not open, your MAPI is probably not set up correctly and this step may not work either.