Using Javascript send PDF to a defined email address via dialog
Copy link to clipboard
Copied
Hi! I have below javascipt for Adobe Acrobat Pro DC. But after I enter the email address in the dialog, I get Missing Arguments error. Appreciate your help!
try {
// Get the current document
var currentDoc = this;
// Prompt the user for recipient's email address
var emailAddress = app.response("Enter recipient's email address:", "Recipient's Email");
if (emailAddress !== null && emailAddress !== "") {
// Get the file path of the current document
var filePath = currentDoc.path;
//Convert filePath to a clickable path
var link = "<a href=\"file:///" + filePath + "\">" + filePath + "</a>";
// Create an email data object with user input and default values
var emailData = {
cTo: emailAddress,
cSubject: "For Your Review and Signature",
cMsg: "Please review and sign the documents located at:\n" +link,
cCc: "", // Add CC recipients if needed
cBcc: "", // Add BCC recipients if needed
oAttachments: [currentDoc.path]
};
// Send the email using AcroSendMail:SendMail action
app.mailMsg(emailData);
}
} catch (e) {
app.alert("Error occurred: " + e.message, 0);
}
Copy link to clipboard
Copied
Couple of issues there:
1. You can't include links in the email message body. It's pure text, not HTML.
2. I'm not familiar with the oAttachments parameter, and it's undocumented.
3. Be aware that mailMsg will only work in Acrobat, not in Reader.
4. When you get an error message it's always a good idea to see it in full. To do that you should remove your try-catch clause. Then you'll see that the full error message says:
MissingArgError: Missing required argument.
App.mailMsg:26:Console undefined:Exec
===> Parameter bUI.
And how you know what parameter you're missing...
The solution for both #2 and #3 is to use the mailDoc of the Document object, instead of mailMsg, which automatically attaches the current file, AND works in Reader.
Copy link to clipboard
Copied
Thanks for the reply!
1. I've tested this on a different script and I can include clickable links in the email.
2. Yes, will just try to remove this instead since the email contains links.
3. Yes I am using Acrobat Pro.
4. I removed the try and catch clause.
Looks like mailDoc is not a built-in method for sending emails directly in Adobe...
Copy link to clipboard
Copied
1. Then you lucked out with an email client that auto-detects HTML tags, but it will not work in all environments.
3. Are you the only one who's going to use this file, though? Because if someone with Reader will try to use it, it won't work if you continue having app.mailMsg...
5. mailDoc is most certainly a built-in method in Acrobat (and Reader) for sending emails, although not on mobile devices. What exactly happens when you try to use it?

