Copy link to clipboard
Copied
Hi! I have below script. I need to email currently opened PDF to a defined email address but I get the return error in my code "An error occured while sending the email". Any thoughts appreciated! Thank you.
// Prompt the user for an email address
var emailAddress = app.response({
cQuestion: "Enter recipient's email address:",
cTitle: "Email Document",
cDefault: "recipient@example.com"
});
// Get the currently opened document
var currentDoc = app.activeDocs[0];
// Get the file path of the current document
var filePath = currentDoc.path;
//Convert filePath to a clickable path
var link = "<a href=\"file:///" + filePath + "\">" + "</a>";
// Check if a document is currently open
if (currentDoc) {
// Create a new email object
var mailObj = {
cTo: emailAddress,
cSubject: "For Your Review and Signature",
cMsg: "Please review and sign the document(s) located at:\n" +link,
cCc: "", // Add CC recipients if needed
cBcc: "", // Add BCC recipients if needed
};
// Try sending the email
try {
app.mailMsg(mailObj);
// Show success dialog
app.alert("Email sent successfully.", 3); // 3 represents an Information icon
} catch (e) {
console.println("Error sending email: " + e);
app.alert("An error occurred while sending the email.", 1); // 1 represents an Error icon
}
} else {
app.alert("No document open.", 1);
}
Have something to add?