💬 ♻️ signed mail template

This commit is contained in:
Timur Ercan
2023-02-21 17:42:30 +01:00
parent 12a8a1ddc0
commit 21794a860d
8 changed files with 82 additions and 33 deletions

View File

@ -1,28 +1,13 @@
import { NEXT_PUBLIC_WEBAPP_URL } from "../constants";
import { Document as PrismaDocument } from "@prisma/client";
export const transactionEmailTemplate = (
message: string,
document: any,
recipient: any,
ctaLink: string,
ctaLabel: string,
user: any
) => {
export const baseEmailTemplate = (message: string, content: string) => {
const html = `
<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">
<img src="${NEXT_PUBLIC_WEBAPP_URL}/logo_h.png" alt="Documenso Logo" style="width: 180px; display: block; margin: auto; margin-bottom: 14px;">
${message}
<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">
${content}
</div>
`;
@ -31,7 +16,7 @@ export const transactionEmailTemplate = (
<div>
<b>Do not forward.</b>
<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 style="margin-top: 12px">
<b>Need help?</b>
@ -49,4 +34,4 @@ export const transactionEmailTemplate = (
return html + footer;
};
export default transactionEmailTemplate;
export default baseEmailTemplate;

View File

@ -1,3 +1,4 @@
export { signingRequestTemplate } from "./signingRequestTemplate";
export { signingCompleteTemplate } from "./signingCompleteTemplate";
export { sendSigningRequest as sendSigningRequest } from "./sendSigningRequest";
export { sendSigningDoneMail } from "./sendSigningDoneMail";
export { transactionEmailTemplate } from "./transactionEmailTemplate";

View File

@ -1,7 +1,16 @@
import { ReadStream } from "fs";
import nodemailer from "nodemailer";
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)
throw new Error("Sendgrid API Key not set.");
@ -16,6 +25,7 @@ export const sendMail = async (to: string, subject: string, body: string) => {
to: to,
subject: subject,
html: body,
attachments: attachments,
})
.catch((err) => {
throw err;

View File

@ -1,23 +1,22 @@
import { sendMail } from "./sendMail";
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 (
recipient: any,
document: any,
user: any
) => {
// todo check if recipient has an account
await sendMail(
user.email,
`Completed: "${document.title}"`,
transactionEmailTemplate(
`All recipients have signed "${document.title}"`,
document,
recipient,
`${NEXT_PUBLIC_WEBAPP_URL}/api/documents/${document.id}`,
`Download "${document.title}"`,
user
)
// base template with footer and box vs content template for eact type
signingCompleteTemplate(`All recipients have signed "${document.title}".`),
[
{
filename: document.title,
content: Buffer.from(document.document.toString(), "base64"),
},
]
);
};

View File

@ -2,7 +2,7 @@ import prisma from "@documenso/prisma";
import { sendMail } from "./sendMail";
import { SendStatus, DocumentStatus } from "@prisma/client";
import { NEXT_PUBLIC_WEBAPP_URL } from "../constants";
import { transactionEmailTemplate } from "@documenso/lib/mail";
import { signingRequestTemplate } from "@documenso/lib/mail";
export const sendSigningRequest = async (
recipient: any,
@ -12,7 +12,7 @@ export const sendSigningRequest = async (
await sendMail(
user.email,
`Please sign ${document.title}`,
transactionEmailTemplate(
signingRequestTemplate(
`${user.name} (${user.email}) has sent you a document to sign. `,
document,
recipient,

View 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;

View 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;