mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 00:32:43 +10:00
💬 ♻️ signed mail template
This commit is contained in:
BIN
apps/web/public/images/signed_100.png
Normal file
BIN
apps/web/public/images/signed_100.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
@ -1,28 +1,13 @@
|
|||||||
import { NEXT_PUBLIC_WEBAPP_URL } from "../constants";
|
import { NEXT_PUBLIC_WEBAPP_URL } from "../constants";
|
||||||
import { Document as PrismaDocument } from "@prisma/client";
|
import { Document as PrismaDocument } from "@prisma/client";
|
||||||
|
|
||||||
export const transactionEmailTemplate = (
|
export const baseEmailTemplate = (message: string, content: string) => {
|
||||||
message: string,
|
|
||||||
document: any,
|
|
||||||
recipient: any,
|
|
||||||
ctaLink: string,
|
|
||||||
ctaLabel: string,
|
|
||||||
user: any
|
|
||||||
) => {
|
|
||||||
const html = `
|
const html = `
|
||||||
<div style="background-color: #eaeaea; padding: 2%;">
|
<div style="background-color: #eaeaea; padding: 2%;">
|
||||||
<div style="text-align:center; margin: auto; font-size: 14px; font-color: #353434; max-width: 500px; border-radius: 0.375rem; background: white; padding: 50px">
|
<div style="text-align:center; margin: auto; font-size: 14px; font-color: #353434; max-width: 500px; border-radius: 0.375rem; background: white; padding: 50px">
|
||||||
<img src="${NEXT_PUBLIC_WEBAPP_URL}/logo_h.png" alt="Documenso Logo" style="width: 180px; display: block; margin: auto; margin-bottom: 14px;">
|
<img src="${NEXT_PUBLIC_WEBAPP_URL}/logo_h.png" alt="Documenso Logo" style="width: 180px; display: block; margin: auto; margin-bottom: 14px;">
|
||||||
${message}
|
${message}
|
||||||
<p style="margin: 30px;">
|
${content}
|
||||||
<a href="${ctaLink}" style="background-color: #37f095; color: white; border-color: transparent; border-width: 1px; border-radius: 0.375rem; font-size: 18px; padding-left: 16px; padding-right: 16px; padding-top: 10px; padding-bottom: 10px; text-decoration: none; margin-top: 4px; margin-bottom: 4px;">
|
|
||||||
${ctaLabel}
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
<hr size="1" style="height:1px;border:none;color:#e0e0e0;background-color:#e0e0e0">
|
|
||||||
Click the button to view "${document.title}".<br>
|
|
||||||
<small>If you have questions about this document, you should ask ${user.name}.</small>
|
|
||||||
<hr size="1" style="height:1px;border:none;color:#e0e0e0;background-color:#e0e0e0">
|
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@ -31,7 +16,7 @@ export const transactionEmailTemplate = (
|
|||||||
<div>
|
<div>
|
||||||
<b>Do not forward.</b>
|
<b>Do not forward.</b>
|
||||||
<br>
|
<br>
|
||||||
This email contains a link to a secure document. Keep it secret and do not forward this email.
|
This email gives access to a secure document. Keep it secret and do not forward this email.
|
||||||
</div>
|
</div>
|
||||||
<div style="margin-top: 12px">
|
<div style="margin-top: 12px">
|
||||||
<b>Need help?</b>
|
<b>Need help?</b>
|
||||||
@ -49,4 +34,4 @@ export const transactionEmailTemplate = (
|
|||||||
return html + footer;
|
return html + footer;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default transactionEmailTemplate;
|
export default baseEmailTemplate;
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
export { signingRequestTemplate } from "./signingRequestTemplate";
|
||||||
|
export { signingCompleteTemplate } from "./signingCompleteTemplate";
|
||||||
export { sendSigningRequest as sendSigningRequest } from "./sendSigningRequest";
|
export { sendSigningRequest as sendSigningRequest } from "./sendSigningRequest";
|
||||||
export { sendSigningDoneMail } from "./sendSigningDoneMail";
|
export { sendSigningDoneMail } from "./sendSigningDoneMail";
|
||||||
export { transactionEmailTemplate } from "./transactionEmailTemplate";
|
|
||||||
|
|||||||
@ -1,7 +1,16 @@
|
|||||||
|
import { ReadStream } from "fs";
|
||||||
import nodemailer from "nodemailer";
|
import nodemailer from "nodemailer";
|
||||||
import nodemailerSendgrid from "nodemailer-sendgrid";
|
import nodemailerSendgrid from "nodemailer-sendgrid";
|
||||||
|
|
||||||
export const sendMail = async (to: string, subject: string, body: string) => {
|
export const sendMail = async (
|
||||||
|
to: string,
|
||||||
|
subject: string,
|
||||||
|
body: string,
|
||||||
|
attachments: {
|
||||||
|
filename: string;
|
||||||
|
content: string | Buffer;
|
||||||
|
}[] = []
|
||||||
|
) => {
|
||||||
if (!process.env.SENDGRID_API_KEY)
|
if (!process.env.SENDGRID_API_KEY)
|
||||||
throw new Error("Sendgrid API Key not set.");
|
throw new Error("Sendgrid API Key not set.");
|
||||||
|
|
||||||
@ -16,6 +25,7 @@ export const sendMail = async (to: string, subject: string, body: string) => {
|
|||||||
to: to,
|
to: to,
|
||||||
subject: subject,
|
subject: subject,
|
||||||
html: body,
|
html: body,
|
||||||
|
attachments: attachments,
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw err;
|
throw err;
|
||||||
|
|||||||
@ -1,23 +1,22 @@
|
|||||||
import { sendMail } from "./sendMail";
|
import { sendMail } from "./sendMail";
|
||||||
import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants";
|
import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants";
|
||||||
import { transactionEmailTemplate } from "@documenso/lib/mail";
|
import { signingCompleteTemplate } from "@documenso/lib/mail";
|
||||||
|
|
||||||
export const sendSigningDoneMail = async (
|
export const sendSigningDoneMail = async (
|
||||||
recipient: any,
|
recipient: any,
|
||||||
document: any,
|
document: any,
|
||||||
user: any
|
user: any
|
||||||
) => {
|
) => {
|
||||||
// todo check if recipient has an account
|
|
||||||
await sendMail(
|
await sendMail(
|
||||||
user.email,
|
user.email,
|
||||||
`Completed: "${document.title}"`,
|
`Completed: "${document.title}"`,
|
||||||
transactionEmailTemplate(
|
// base template with footer and box vs content template for eact type
|
||||||
`All recipients have signed "${document.title}"`,
|
signingCompleteTemplate(`All recipients have signed "${document.title}".`),
|
||||||
document,
|
[
|
||||||
recipient,
|
{
|
||||||
`${NEXT_PUBLIC_WEBAPP_URL}/api/documents/${document.id}`,
|
filename: document.title,
|
||||||
`Download "${document.title}"`,
|
content: Buffer.from(document.document.toString(), "base64"),
|
||||||
user
|
},
|
||||||
)
|
]
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import prisma from "@documenso/prisma";
|
|||||||
import { sendMail } from "./sendMail";
|
import { sendMail } from "./sendMail";
|
||||||
import { SendStatus, DocumentStatus } from "@prisma/client";
|
import { SendStatus, DocumentStatus } from "@prisma/client";
|
||||||
import { NEXT_PUBLIC_WEBAPP_URL } from "../constants";
|
import { NEXT_PUBLIC_WEBAPP_URL } from "../constants";
|
||||||
import { transactionEmailTemplate } from "@documenso/lib/mail";
|
import { signingRequestTemplate } from "@documenso/lib/mail";
|
||||||
|
|
||||||
export const sendSigningRequest = async (
|
export const sendSigningRequest = async (
|
||||||
recipient: any,
|
recipient: any,
|
||||||
@ -12,7 +12,7 @@ export const sendSigningRequest = async (
|
|||||||
await sendMail(
|
await sendMail(
|
||||||
user.email,
|
user.email,
|
||||||
`Please sign ${document.title}`,
|
`Please sign ${document.title}`,
|
||||||
transactionEmailTemplate(
|
signingRequestTemplate(
|
||||||
`${user.name} (${user.email}) has sent you a document to sign. `,
|
`${user.name} (${user.email}) has sent you a document to sign. `,
|
||||||
document,
|
document,
|
||||||
recipient,
|
recipient,
|
||||||
|
|||||||
25
packages/lib/mail/signingCompleteTemplate.ts
Normal file
25
packages/lib/mail/signingCompleteTemplate.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { NEXT_PUBLIC_WEBAPP_URL } from "../constants";
|
||||||
|
import { Document as PrismaDocument } from "@prisma/client";
|
||||||
|
import { baseEmailTemplate } from "./baseTemplate";
|
||||||
|
|
||||||
|
export const signingCompleteTemplate = (message: string) => {
|
||||||
|
const customContent = `
|
||||||
|
<div style="
|
||||||
|
width: 100px;
|
||||||
|
height: 100px;
|
||||||
|
margin: auto;
|
||||||
|
padding-top: 14px;
|
||||||
|
">
|
||||||
|
<img src="${NEXT_PUBLIC_WEBAPP_URL}/images/signed_100.png" alt="Documenso Logo" style="width: 100px; display: block;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p style="margin-top: 14px;">
|
||||||
|
A copy of the signed document has been attached to this email.
|
||||||
|
</p>`;
|
||||||
|
|
||||||
|
const html = baseEmailTemplate(message, customContent);
|
||||||
|
|
||||||
|
return html;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default signingCompleteTemplate;
|
||||||
29
packages/lib/mail/signingRequestTemplate.ts
Normal file
29
packages/lib/mail/signingRequestTemplate.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { NEXT_PUBLIC_WEBAPP_URL } from "../constants";
|
||||||
|
import { Document as PrismaDocument } from "@prisma/client";
|
||||||
|
import { baseEmailTemplate } from "./baseTemplate";
|
||||||
|
|
||||||
|
export const signingRequestTemplate = (
|
||||||
|
message: string,
|
||||||
|
document: any,
|
||||||
|
recipient: any,
|
||||||
|
ctaLink: string,
|
||||||
|
ctaLabel: string,
|
||||||
|
user: any
|
||||||
|
) => {
|
||||||
|
const customContent = `
|
||||||
|
<p style="margin: 30px;">
|
||||||
|
<a href="${ctaLink}" style="background-color: #37f095; color: white; border-color: transparent; border-width: 1px; border-radius: 0.375rem; font-size: 18px; padding-left: 16px; padding-right: 16px; padding-top: 10px; padding-bottom: 10px; text-decoration: none; margin-top: 4px; margin-bottom: 4px;">
|
||||||
|
${ctaLabel}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<hr size="1" style="height:1px;border:none;color:#e0e0e0;background-color:#e0e0e0">
|
||||||
|
Click the button to view "${document.title}".<br>
|
||||||
|
<small>If you have questions about this document, you should ask ${user.name}.</small>
|
||||||
|
<hr size="1" style="height:1px;border:none;color:#e0e0e0;background-color:#e0e0e0">`;
|
||||||
|
|
||||||
|
const html = baseEmailTemplate(message, customContent);
|
||||||
|
|
||||||
|
return html;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default signingRequestTemplate;
|
||||||
Reference in New Issue
Block a user