How to Send a PDF by Email Using Acrobat mailDoc() JavaScript
Question details
The user needs to send a PDF document via email using the mailDoc() JavaScript function in Adobe Acrobat, but the script is failing to execute.

- Product
- Adobe Acrobat Pro DC
- Device & OS
- Windows 10
- Scenario
- Setting up a button with a JavaScript action to automatically attach the current PDF to an email.
- Observed behavior
- The action does not run due to a syntax error in the string assignment, preventing the email client from launching.
Ensure your default email client (such as Outlook or Windows Mail) is properly configured on your Windows 10 device, and verify that Adobe Acrobat's security settings permit JavaScript execution.
Fix the Syntax Error and Trigger mailDoc() via User Action
Correct the JavaScript string syntax in your variable assignment and ensure the script is executed via a permitted user action like a Mouse Up event.
Adobe Acrobat requires specific formatting for JavaScript execution. A common mistake is terminating a string concatenation with a period instead of a semicolon. Additionally, for security reasons, functions like mailDoc() must be triggered by an explicit user action rather than running automatically.
In Adobe Acrobat Pro DC, enter 'Prepare Form' mode. Right-click the button intended to trigger the email and select 'Properties'.
Navigate to the 'Actions' tab. Select 'Mouse Up' as the trigger event, choose 'Run a JavaScript' from the 'Select Action' dropdown, and click 'Add'.
Fix the syntax error in your variable assignment by replacing the trailing period with a semicolon. For example: var cBody = 'Please find the attached document for ' + this.getField('NAME').value;
On the next line, execute the method by adding: this.mailDoc({bUI: true, cTo: 'example@email.com', cMsg: cBody}); Click 'OK' to save the script.
Exit form editing mode and click your button. Your default email client will open with the PDF attached and the message body pre-filled.

Send PDFs by Email Instantly with WPS Office
If configuring JavaScript and debugging code in Adobe Acrobat is too complex, WPS Office provides a built-in, one-click solution to send any PDF document as an email attachment without writing a single line of code.
- 1. Open your PDF in WPS: Launch WPS Office and open the PDF document you wish to share via email.
- 2. Locate the Share Function: Navigate to the top toolbar of the WPS PDF interface and click on the 'Share' or 'Email' icon.
- 3. Launch Email Client: Select 'Email'. WPS Office will automatically launch your default desktop email client with the PDF document already attached.
- 4. Send the Document: Fill in the recipient's email address, add your desired subject line, and hit send.

Frequently Asked Questions
Why isn't the mailDoc() function opening my email client?
This usually occurs if there is a syntax error in your JavaScript code, if Acrobat's security settings are blocking the action, or if your default email application is not correctly designated in your Windows 10 OS settings.
Can I automatically send the PDF without user interaction using mailDoc?
No, Adobe Acrobat's security model dictates that the mailDoc() method must be triggered by a direct, permitted user action, such as a 'Mouse Up' event on a form button.
How do I dynamically attach form field data into the email body?
You can retrieve form data using this.getField('FieldName').value and concatenate it into your message string before passing that string to the cMsg parameter of the mailDoc() function.




