mirror of
https://github.com/documenso/documenso.git
synced 2025-11-18 02:32:00 +10:00
nodemailer and sendgrid integration
This commit is contained in:
@ -0,0 +1,2 @@
|
||||
export { sendSigningRequestMail } from "./sendSigningRequestMail";
|
||||
export { sendSignedMail } from "./sendSignedMail";
|
||||
|
||||
24
packages/lib/mail/sendMail.ts
Normal file
24
packages/lib/mail/sendMail.ts
Normal file
@ -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,
|
||||
});
|
||||
};
|
||||
12
packages/lib/mail/sendSignedMail.ts
Normal file
12
packages/lib/mail/sendSignedMail.ts
Normal file
@ -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.`
|
||||
);
|
||||
};
|
||||
@ -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.`
|
||||
);
|
||||
};
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
// nodemailer
|
||||
// sendgrid
|
||||
Reference in New Issue
Block a user