Skip to content

Commit 80d3200

Browse files
fix: valid file is not attached to mail in signyourself flow
1 parent 7708b7e commit 80d3200

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

apps/OpenSign/src/components/pdf/EmailComponent.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ function EmailComponent({
2929
const pdfName = pdfDetails[0]?.Name;
3030
setIsLoading(true);
3131
let sendMail;
32+
33+
const docId = !pdfDetails?.[0]?.IsEnableOTP
34+
? pdfDetails?.[0]?.objectId
35+
: "";
36+
let presignedUrl = pdfUrl;
37+
try {
38+
// const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
39+
const axiosRes = await axios.post(
40+
`${localStorage.getItem("baseUrl")}/functions/getsignedurl`,
41+
{ url: pdfUrl, docId: docId },
42+
{
43+
headers: {
44+
"content-type": "Application/json",
45+
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
46+
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
47+
}
48+
}
49+
);
50+
presignedUrl = axiosRes.data.result;
51+
} catch (err) {
52+
console.log("err in getsignedurl", err);
53+
}
3254
for (let i = 0; i < emailList.length; i++) {
3355
try {
3456
const imgPng =
@@ -46,7 +68,7 @@ function EmailComponent({
4668
mailProvider: activeMailAdapter,
4769
extUserId: extUserId,
4870
pdfName: pdfName,
49-
url: pdfUrl,
71+
url: presignedUrl,
5072
recipient: emailList[i],
5173
subject: `${sender.name} has signed the doc - ${pdfName}`,
5274
from: sender.email,

apps/OpenSignServer/cloud/parsefunction/sendMailGmailProvider.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,26 @@ const makeEmail = async (to, from, subject, html, url, pdfName) => {
6868
type: 'application/pdf',
6969
path: './exports/certificate.pdf',
7070
};
71-
attachments = [file, certificate];
71+
if (fs.existsSync(certificate.path)) {
72+
attachments = [file, certificate];
73+
} else {
74+
attachments = [file];
75+
}
7276
} catch (err) {
7377
attachments = [file];
7478
console.log('Err in read certificate sendmailv3', err);
7579
}
7680
}
7781
const attachmentParts = attachments.map(attachment => {
78-
if (fs.existsSync(attachment.path)) {
79-
try {
80-
const content = fs.readFileSync(attachment.path);
81-
const encodedContent = content.toString('base64');
82-
return [
83-
`Content-Type: ${attachment.type}\n`,
84-
'MIME-Version: 1.0\n',
85-
`Content-Disposition: attachment; filename="${attachment.filename}"\n`,
86-
`Content-Transfer-Encoding: base64\n\n`,
87-
`${encodedContent}\n`,
88-
].join('');
89-
} catch (err) {
90-
console.log('Err in read attachments sendmailv3', attachment.path);
91-
}
92-
}
82+
const content = fs.readFileSync(attachment.path);
83+
const encodedContent = content.toString('base64');
84+
return [
85+
`Content-Type: ${attachment.type}\n`,
86+
'MIME-Version: 1.0\n',
87+
`Content-Disposition: attachment; filename="${attachment.filename}"\n`,
88+
`Content-Transfer-Encoding: base64\n\n`,
89+
`${encodedContent}\n`,
90+
].join('');
9391
});
9492

9593
const attachmentBody = attachmentParts.join(`\n--${boundary}\n`);
@@ -149,6 +147,14 @@ export default async function sendMailGmailProvider(_extRes, template) {
149147
},
150148
});
151149
console.log('gmail provider res: ', response?.status);
150+
const certificatePath = './exports/certificate.pdf';
151+
if (fs.existsSync(certificatePath)) {
152+
try {
153+
fs.unlinkSync(certificatePath);
154+
} catch (err) {
155+
console.log('Err in unlink certificate sendmailgmail provider');
156+
}
157+
}
152158
return { code: 200, message: 'Email sent successfully' };
153159
} catch (error) {
154160
console.error('Error sending email:', error);

0 commit comments

Comments
 (0)