From 333d1610fad10e70759545f223959503288a02c6 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Thu, 10 Jul 2025 19:34:31 +0000 Subject: feat: Add invite user support --- packages/trpc/email.ts | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'packages/trpc/email.ts') diff --git a/packages/trpc/email.ts b/packages/trpc/email.ts index 2ca3e396..ded23ed8 100644 --- a/packages/trpc/email.ts +++ b/packages/trpc/email.ts @@ -108,3 +108,64 @@ export async function verifyEmailToken( return true; } + +export async function sendInviteEmail( + email: string, + token: string, + inviterName: string, +) { + if (!serverConfig.email.smtp) { + throw new Error("SMTP is not configured"); + } + + const transporter = createTransport({ + host: serverConfig.email.smtp.host, + port: serverConfig.email.smtp.port, + secure: serverConfig.email.smtp.secure, + auth: + serverConfig.email.smtp.user && serverConfig.email.smtp.password + ? { + user: serverConfig.email.smtp.user, + pass: serverConfig.email.smtp.password, + } + : undefined, + }); + + const inviteUrl = `${serverConfig.publicUrl}/invite/${encodeURIComponent(token)}`; + + const mailOptions = { + from: serverConfig.email.smtp.from, + to: email, + subject: "You've been invited to join Karakeep", + html: ` +
+

You've been invited to join Karakeep!

+

${inviterName} has invited you to join Karakeep, the bookmark everything app.

+

Click the link below to accept your invitation and create your account:

+

+ + Accept Invitation + +

+

If the button doesn't work, you can copy and paste this link into your browser:

+

${inviteUrl}

+

This invitation will expire in 7 days.

+

If you weren't expecting this invitation, you can safely ignore this email.

+
+ `, + text: ` +You've been invited to join Karakeep! + +${inviterName} has invited you to join Karakeep, a powerful bookmarking and content organization platform. + +Accept your invitation by visiting this link: +${inviteUrl} + +This invitation will expire in 7 days. + +If you weren't expecting this invitation, you can safely ignore this email. + `, + }; + + await transporter.sendMail(mailOptions); +} -- cgit v1.2.3-70-g09d2