mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
Merge pull request #1258 from OpenSignLabs/validation
fix: valid file is not attached to mail in signyourself flow
This commit is contained in:
@@ -30,6 +30,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 =
|
||||
@@ -47,7 +69,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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user