Skip to content

The Open Source DocuSign Alternative.

fix: attach document to completed email

Mythie9d9b1a6681b5
diff --git a/packages/lib/server-only/document/send-completed-email.ts b/packages/lib/server-only/document/send-completed-email.ts
index 9d0d2d499..bb6d06b41 100644
--- a/packages/lib/server-only/document/send-completed-email.ts
+++ b/packages/lib/server-only/document/send-completed-email.ts
@@ -5,6 +5,8 @@ import { render } from '@documenso/email/render';
import { DocumentCompletedEmailTemplate } from '@documenso/email/templates/document-completed';
import { prisma } from '@documenso/prisma';
+import { getFile } from '../../universal/upload/get-file';
+
export interface SendDocumentOptions {
documentId: number;
}
@@ -15,6 +17,7 @@ export const sendCompletedEmail = async ({ documentId }: SendDocumentOptions) =>
id: documentId,
},
include: {
+ documentData: true,
Recipient: true,
},
});
@@ -27,6 +30,8 @@ export const sendCompletedEmail = async ({ documentId }: SendDocumentOptions) =>
throw new Error('Document has no recipients');
}
+ const buffer = await getFile(document.documentData);
+
await Promise.all([
document.Recipient.map(async (recipient) => {
const { email, name, token } = recipient;
@@ -51,6 +56,12 @@ export const sendCompletedEmail = async ({ documentId }: SendDocumentOptions) =>
subject: 'Signing Complete!',
html: render(template),
text: render(template, { plainText: true }),
+ attachments: [
+ {
+ filename: document.title,
+ content: Buffer.from(buffer),
+ },
+ ],
});
}),
]);