Skip to content

🔥 The free & Open Source DocuSign alternative

fix: valid file is not attached to mail in signyourself flow

prafull-opensignlabs80d3200d5783
diff --git a/apps/OpenSign/src/components/pdf/EmailComponent.js b/apps/OpenSign/src/components/pdf/EmailComponent.js
index c3b9f4b1a..3c67ccb0f 100644
--- a/apps/OpenSign/src/components/pdf/EmailComponent.js
+++ b/apps/OpenSign/src/components/pdf/EmailComponent.js
@@ -29,6 +29,28 @@ function EmailComponent({
const pdfName = pdfDetails[0]?.Name;
setIsLoading(true);
let sendMail;
+
+ const docId = !pdfDetails?.[0]?.IsEnableOTP
+ ? pdfDetails?.[0]?.objectId
+ : "";
+ let presignedUrl = pdfUrl;
+ try {
+ // const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
+ const axiosRes = await axios.post(
+ `${localStorage.getItem("baseUrl")}/functions/getsignedurl`,
+ { url: pdfUrl, docId: docId },
+ {
+ headers: {
+ "content-type": "Application/json",
+ "X-Parse-Application-Id": localStorage.getItem("parseAppId"),
+ "X-Parse-Session-Token": localStorage.getItem("accesstoken")
+ }
+ }
+ );
+ presignedUrl = axiosRes.data.result;
+ } catch (err) {
+ console.log("err in getsignedurl", err);
+ }
for (let i = 0; i < emailList.length; i++) {
try {
const imgPng =
@@ -46,7 +68,7 @@ function EmailComponent({
mailProvider: activeMailAdapter,
extUserId: extUserId,
pdfName: pdfName,
- url: pdfUrl,
+ url: presignedUrl,
recipient: emailList[i],
subject: `${sender.name} has signed the doc - ${pdfName}`,
from: sender.email,
diff --git a/apps/OpenSignServer/cloud/parsefunction/sendMailGmailProvider.js b/apps/OpenSignServer/cloud/parsefunction/sendMailGmailProvider.js
index b3f8c10cd..dae9ec9af 100644
--- a/apps/OpenSignServer/cloud/parsefunction/sendMailGmailProvider.js
+++ b/apps/OpenSignServer/cloud/parsefunction/sendMailGmailProvider.js
@@ -68,28 +68,26 @@ const makeEmail = async (to, from, subject, html, url, pdfName) => {
type: 'application/pdf',
path: './exports/certificate.pdf',
};
- attachments = [file, certificate];
+ if (fs.existsSync(certificate.path)) {
+ attachments = [file, certificate];
+ } else {
+ attachments = [file];
+ }
} catch (err) {
attachments = [file];
console.log('Err in read certificate sendmailv3', err);
}
}
const attachmentParts = attachments.map(attachment => {
- if (fs.existsSync(attachment.path)) {
- try {
- const content = fs.readFileSync(attachment.path);
- const encodedContent = content.toString('base64');
- return [
- `Content-Type: ${attachment.type}\n`,
- 'MIME-Version: 1.0\n',
- `Content-Disposition: attachment; filename="${attachment.filename}"\n`,
- `Content-Transfer-Encoding: base64\n\n`,
- `${encodedContent}\n`,
- ].join('');
- } catch (err) {
- console.log('Err in read attachments sendmailv3', attachment.path);
- }
- }
+ const content = fs.readFileSync(attachment.path);
+ const encodedContent = content.toString('base64');
+ return [
+ `Content-Type: ${attachment.type}\n`,
+ 'MIME-Version: 1.0\n',
+ `Content-Disposition: attachment; filename="${attachment.filename}"\n`,
+ `Content-Transfer-Encoding: base64\n\n`,
+ `${encodedContent}\n`,
+ ].join('');
});
const attachmentBody = attachmentParts.join(`\n--${boundary}\n`);
@@ -149,6 +147,14 @@ export default async function sendMailGmailProvider(_extRes, template) {
},
});
console.log('gmail provider res: ', response?.status);
+ const certificatePath = './exports/certificate.pdf';
+ if (fs.existsSync(certificatePath)) {
+ try {
+ fs.unlinkSync(certificatePath);
+ } catch (err) {
+ console.log('Err in unlink certificate sendmailgmail provider');
+ }
+ }
return { code: 200, message: 'Email sent successfully' };
} catch (error) {
console.error('Error sending email:', error);