Skip to content

The Open Source DocuSign Alternative.

nodemailer and sendgrid integration

Timur Ercan58fb62b94bbb
diff --git a/apps/web/package.json b/apps/web/package.json
index 7dfa51a10..b6c0561c0 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -16,7 +16,6 @@
"@tailwindcss/forms": "^0.5.3",
"@types/bcryptjs": "^2.4.2",
"@types/filesystem": "^0.0.32",
- "@types/node": "18.11.9",
"@types/react-dom": "18.0.9",
"avatar-from-initials": "^1.0.3",
"bcryptjs": "^2.4.3",
@@ -29,6 +28,10 @@
"next": "13.0.3",
"next-auth": "^4.18.3",
"next-transpile-modules": "^10.0.0",
+ "node-forge": "^1.3.1",
+ "node-signpdf": "^1.5.0",
+ "nodemailer": "^6.9.0",
+ "nodemailer-sendgrid": "^1.0.3",
"npm": "^9.1.3",
"placeholder-loading": "^0.6.0",
"react": "18.2.0",
@@ -40,6 +43,9 @@
},
"devDependencies": {
"@types/formidable": "^2.0.5",
+ "@types/node": "^18.11.18",
+ "@types/nodemailer": "^6.4.7",
+ "@types/nodemailer-sendgrid": "^1.0.0",
"@types/react-pdf": "^6.2.0",
"autoprefixer": "^10.4.13",
"postcss": "^8.4.19",
diff --git a/packages/lib/mail/index.ts b/packages/lib/mail/index.ts
index e69de29bb..17887b36f 100644
--- a/packages/lib/mail/index.ts
+++ b/packages/lib/mail/index.ts
@@ -0,0 +1,2 @@
+export { sendSigningRequestMail } from "./sendSigningRequestMail";
+export { sendSignedMail } from "./sendSignedMail";
diff --git a/packages/lib/mail/sendMail.ts b/packages/lib/mail/sendMail.ts
new file mode 100644
index 000000000..1c9b314e0
--- /dev/null
+++ b/packages/lib/mail/sendMail.ts
@@ -0,0 +1,24 @@
+import nodemailer from "nodemailer";
+import nodemailerSendgrid from "nodemailer-sendgrid";
+
+export const sendMail = async (
+ to: string,
+ subject: string,
+ htmlFormattedMessage: string
+) => {
+ if (!process.env.SENDGRID_API_KEY)
+ throw new Error("Sendgrid API Key not set.");
+
+ const transport = nodemailer.createTransport(
+ nodemailerSendgrid({
+ apiKey: process.env.SENDGRID_API_KEY || "",
+ })
+ );
+
+ await transport.sendMail({
+ from: process.env.SENDGRID_API_KEY,
+ to: to,
+ subject: subject,
+ html: htmlFormattedMessage,
+ });
+};
diff --git a/packages/lib/mail/sendSignedMail.ts b/packages/lib/mail/sendSignedMail.ts
new file mode 100644
index 000000000..bbed16a9b
--- /dev/null
+++ b/packages/lib/mail/sendSignedMail.ts
@@ -0,0 +1,12 @@
+import { sendMail } from "./sendMail";
+import { NEXT_PUBLIC_WEBAPP_URL } from "@documenso/lib/constants";
+
+export const sendSignedMail = async (document: any, recipient: any) => {
+ // todo check if recipient has an account
+
+ sendMail(
+ document.user.email,
+ `${recipient.email} signed ${document.title}`,
+ `Hi ${document.user.name}, ${recipient.email} has signed your document ${document.title}. Click <a href="${NEXT_PUBLIC_WEBAPP_URL}/document/${document.id}"> VIEW DOCUMENT</a> to view it now.`
+ );
+};
diff --git a/packages/lib/mail/sendSigningRequestMail.ts b/packages/lib/mail/sendSigningRequestMail.ts
index e69de29bb..23942e9ff 100644
--- a/packages/lib/mail/sendSigningRequestMail.ts
+++ b/packages/lib/mail/sendSigningRequestMail.ts
@@ -0,0 +1,9 @@
+import { sendMail } from "./sendMail";
+
+export const sendSigningRequestMail = async (recipient: any, document: any) => {
+ sendMail(
+ recipient.email,
+ `Please sign ${document.title}`,
+ `${document.user.name} has sent you a document to sign. Click <b><a href="https">SIGN DOCUMENT</a></b> to sign it now.`
+ );
+};
diff --git a/packages/lib/mail/sendSigningStatusChangedMail.ts b/packages/lib/mail/sendSigningStatusChangedMail.ts
deleted file mode 100644
index 7f21239e3..000000000
--- a/packages/lib/mail/sendSigningStatusChangedMail.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-// nodemailer
-// sendgrid