Automating Document Emailing via Command-Line BAT or PowerShell Script

AutoDocMail for Adobe® Acrobat®

Introduction
It is possible to automatically distribute PDF files via AutoDocMail by starting processing from outside of Adobe Acrobat via a command-line BAT file. Use this method to automate document email distribution by starting the processing from another application, script or Windows Task Scheduler. You would need to configure the AutoDocMail settings configuration using a regular method (via a user interface) prior to running it via a BAT file. This functionality is available in AutoDocMail version 3.8.2 and up.
Running from command-line file is especially useful when input PDF contains multiple sub-documents that need to be split as separate PDF files and emailed to different recipients. It is not convenient for processing many existing PDF files.
Configure Document Emailing Settings
If you do not have existing settings you want to run via BAT file, then you can create a new named settings configuration via user interface. Start Adobe Acrobat and use Menu > Plugins > Auto-Email Documents... menu to create a new document processing settings configuration.
Create a BAT File
Use any plain text editor (such as Notepad) to create a blank text file. Add the following 3 lines to the file. Make sure to replace paths and filenames with the actual filenames you are using. The example below shows how to start Acrobat DC and process Bulk Forms.pdf PDF file using the Statements named settings.
Here is an example of BAT file for 64-bit Adobe Acrobat:
SET AUTODOCMAIL_INPUT_FILE=C:\Data\Bulk Forms.pdf
SET AUTODOCMAIL_NAMED_SETTINGS=Statements
"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n
Here is an example of BAT file for 32-bit Adobe Acrobat:
SET AUTODOCMAIL_INPUT_FILE=C:\Data\Bulk Forms.pdf
SET AUTODOCMAIL_NAMED_SETTINGS=Statements
"C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n
The environment variable AUTODOCMAIL_INPUT_FILE is used to specify a full file path to the PDF file that needs to be used for the job while AUTODOCMAIL_NAMED_SETTINGS specifies a name of the settings configuration that exists on the current installation of AutoDocMail. AutoDocMail allows to have multiple named settings configurations for processing different kinds of documents.
Save the BAT file with *.bat file extension. Make sure to select a proper file filter in the "Save As" dialog in Notepad to avoid saving the file with a default *.txt file extension.
Run a BAT File
The processing job can be executed by double-clicking on the BAT file in Windows File Explorer window or by running it from another application.
Please note that the BAT file will open Adobe Acrobat and display a progress window during the processing. Use /h switch on the Acrobat's command line to optionally run Adobe Acrobat minimized:
Here is an example of BAT file for 64-bit Adobe Acrobat:
SET AUTODOCMAIL_INPUT_FILE=C:\Data\Bulk Forms.pdf
SET AUTODOCMAIL_NAMED_SETTINGS=Statements
"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n /h
Running AutoDocMail via PowerShell
Here is an example of starting the email job from a PowerShell script. Save the script as *.ps1 file (do not forget to change environment variables to point to actual files on your system), right-click on the file in Windows Explorer and select Run with PowerShell.
# Set environment variables
$env:AUTODOCMAIL_INPUT_FILE = "c:\Data\Bulk Forms.pdf"
$env:AUTODOCMAIL_NAMED_SETTINGS = "Statements"

# Execute Adobe Acrobat natively using the Call operator (&)
& "C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe" /n /h
Starting AutoDocMail from a C# Application
It is also possible to execute a mail merge job from another application. Here is a sample C# code that shows how to launch Adobe Acrobat and pass all necessary parameters via the environmental variables.
System.Diagnostics.Process firstProc = new System.Diagnostics.Process();
firstProc.StartInfo.FileName = @"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe";
firstProc.EnableRaisingEvents = true;
firstProc.StartInfo.UseShellExecute = false;
firstProc.StartInfo.Arguments = @"/n /h"; // pass command-line parameters
firstProc.StartInfo.EnvironmentVariables.Add("AUTODOCMAIL_INPUT_FILE", @"C:\Data\Bulk Form.pdf");
firstProc.StartInfo.EnvironmentVariables.Add("AUTODOCMAIL_NAMED_SETTINGS", @"Statements");
firstProc.Start();