How to Automatically Email a PDF After Saving: Acrobat JS Guide
Question details
The user wants to execute a JavaScript function to automatically generate an email draft with the PDF attached right after the document is saved.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating a fillable PDF form that needs to be emailed back to an administrator immediately upon saving by the client.
- Observed behavior
- The mailDoc script works correctly when attached to a button's Mouse Up event, but the user is struggling to bind it to the document save event automatically.
Ensure you have a desktop PDF editor that supports advanced JavaScript execution and that your default system email client (like Outlook or Apple Mail) is properly configured.
Use a Form Submit Button Instead of a Save Event
Due to security restrictions, auto-emailing on save is discouraged. Using a dedicated Submit button is the safest and most reliable method across different PDF readers.
Modern PDF readers restrict scripts from automatically sending emails without user interaction to prevent malicious activity. Additionally, a document save event can trigger multiple times unnecessarily, repeatedly generating email drafts.
Instead of binding the mailDoc function to a document save action, attach it to a clearly labeled 'Submit' button so the client can consciously approve the action.
Open your PDF in form editing mode and add a new Button field to the document where users can easily see it.
Right-click the button, select 'Properties', and navigate to the 'Actions' tab.
Choose 'Mouse Up' as the trigger, select 'Run a JavaScript' from the Select Action dropdown, and click 'Add'.
Paste your JavaScript code containing the mailDoc function into the editor, click 'OK', and save the PDF. Click the button to test the email generation.

Triggering the Script on Document Will Save
If you strictly require the action to be tied to the save process, use Document Actions to trigger a confirmation alert right before the document saves.
Easily Edit, Save, and Email PDFs with WPS Office
While writing custom JavaScript for PDF forms can be complex and restricted by security settings, WPS Office provides built-in, one-click solutions to save and directly share your PDF documents via email without requiring any coding.
- 1. Open your PDF in WPS Office: Launch WPS Office and open your fillable PDF form using the WPS PDF tool.
- 2. Fill and Save: Complete the form fields as needed and click the 'Save' icon in the quick access toolbar.
- 3. Share via Email: Click the 'Share' or 'Email' button on the top toolbar to automatically attach the saved PDF to a new email draft in your default mail application.

Frequently Asked Questions
Why does the mailDoc function not work on some PDF readers?
Many browser-based or mobile PDF readers do not support Adobe JavaScript APIs like mailDoc due to security restrictions or limited feature sets. A full desktop PDF application is usually required to execute these scripts.
Can a PDF send an email completely in the background without opening an email client?
No. For security and privacy reasons, standard PDF JavaScript cannot silently send an email. It will always create a draft in the user's default desktop email client, requiring them to manually click 'Send'.
How do I conditionally send an email based on form checkboxes?
You can write a JavaScript 'for' loop to iterate through the form's checkbox fields. If the script detects a checked box, it can trigger an app.alert asking the user if they want to email the form before executing the mailDoc action.




