mirror of
https://github.com/documenso/documenso.git
synced 2025-11-16 01:32:06 +10:00
feat: add trpc route to send emails
This commit is contained in:
39
packages/lib/server-only/document/send-document.ts
Normal file
39
packages/lib/server-only/document/send-document.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import nodemailer from 'nodemailer';
|
||||
import nodemailerSendgrid from 'nodemailer-sendgrid';
|
||||
|
||||
export const sendMail = async ({ email }: { email: string }) => {
|
||||
let transporter;
|
||||
|
||||
if (process.env.NEXT_PRIVATE_SENDGRID_API_KEY) {
|
||||
transporter = nodemailer.createTransport(
|
||||
nodemailerSendgrid({
|
||||
apiKey: process.env.NEXT_PRIVATE_SENDGRID_API_KEY,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (process.env.NEXT_PRIVATE_SMTP_MAIL_HOST) {
|
||||
transporter = nodemailer.createTransport({
|
||||
host: process.env.NEXT_PRIVATE_SMTP_MAIL_HOST,
|
||||
port: Number(process.env.NEXT_PRIVATE_SMTP_MAIL_PORT),
|
||||
auth: {
|
||||
user: process.env.NEXT_PRIVATE_SMTP_MAIL_USER,
|
||||
pass: process.env.NEXT_PRIVATE_SMTP_MAIL_PASSWORD,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (!transporter) {
|
||||
throw new Error(
|
||||
'No mail transport configured. Probably Sendgrid API Key nor SMTP Mail host was set',
|
||||
);
|
||||
}
|
||||
|
||||
await transporter.sendMail({
|
||||
from: 'Documenso <hi@documenso.com>',
|
||||
to: email,
|
||||
subject: 'Welcome to Documenso!',
|
||||
text: 'Welcome to Documenso!',
|
||||
html: '<p>Welcome to Documenso!</p>',
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user