mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
fix: valid file is not attached to mail in signyourself flow
This commit is contained in:
@@ -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