From 7572d1a6ff796dd8a4fad5d0feacd7c3301d006f Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Thu, 28 Aug 2025 12:49:05 +0200 Subject: [PATCH] Add email sending --- .../api/src/junk-drawer/private-messages.ts | 3 +++ backend/email/emails/functions/helpers.tsx | 26 +++++++++++++++---- backend/email/emails/functions/send-email.ts | 5 +++- backend/email/emails/new-endorsement.tsx | 4 +-- backend/email/emails/new-match.tsx | 4 +-- backend/email/emails/new-message.tsx | 2 +- backend/email/readme.md | 4 --- 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/backend/api/src/junk-drawer/private-messages.ts b/backend/api/src/junk-drawer/private-messages.ts index 5e6a3502..84bece65 100644 --- a/backend/api/src/junk-drawer/private-messages.ts +++ b/backend/api/src/junk-drawer/private-messages.ts @@ -86,6 +86,7 @@ export const createPrivateUserMessageMain = async ( pg: SupabaseDirectClient, visibility: ChatVisibility ) => { + log('createPrivateUserMessageMain', creator, channelId, content) // Normally, users can only submit messages to channels that they are members of const authorized = await pg.oneOrNone( `select 1 @@ -162,6 +163,7 @@ const notifyOtherUserInChannelIfInactive = async ( // TODO: notification only for active user const otherUser = await getUser(otherUserId.user_id) + console.log('otherUser:', otherUser) if (!otherUser) return await createNewMessageNotification(creator, otherUser, channelId) @@ -173,6 +175,7 @@ const createNewMessageNotification = async ( channelId: number ) => { const privateUser = await getPrivateUser(toUser.id) + console.log('privateUser:', privateUser) if (!privateUser) return await sendNewMessageEmail(privateUser, fromUser, toUser, channelId) } diff --git a/backend/email/emails/functions/helpers.tsx b/backend/email/emails/functions/helpers.tsx index 534e363b..49685064 100644 --- a/backend/email/emails/functions/helpers.tsx +++ b/backend/email/emails/functions/helpers.tsx @@ -6,8 +6,9 @@ import { NewMessageEmail } from '../new-message' import { NewEndorsementEmail } from '../new-endorsement' import { Test } from '../test' import { getLover } from 'shared/love/supabase' +import {renderToStaticMarkup} from "react-dom/server"; -const from = 'Love ' +const from = 'Compass ' export const sendNewMatchEmail = async ( privateUser: PrivateUser, @@ -51,15 +52,30 @@ export const sendNewMessageEmail = async ( const lover = await getLover(fromUser.id) if (!lover) { - console.error('Could not send email notification: Lover not found') + console.error('Could not send email notification: User not found') return } + console.log({ + from, + subject: `${fromUser.name} sent you a message!`, + to: privateUser.email, + html: renderToStaticMarkup( + + ), + }) + return await sendEmail({ from, subject: `${fromUser.name} sent you a message!`, to: privateUser.email, - react: ( + html: renderToStaticMarkup( { return await sendEmail({ from, - subject: 'Test email from Love', + subject: 'Test email from Compass', to: toEmail, - react: , + html: renderToStaticMarkup(), }) } diff --git a/backend/email/emails/functions/send-email.ts b/backend/email/emails/functions/send-email.ts index 06753fcf..4c617242 100644 --- a/backend/email/emails/functions/send-email.ts +++ b/backend/email/emails/functions/send-email.ts @@ -13,10 +13,12 @@ export const sendEmail = async ( options?: CreateEmailRequestOptions ) => { const resend = getResend() + console.log(resend, payload, options) const { data, error } = await resend.emails.send( - { replyTo: 'love@sincl.ai', ...payload }, + { replyTo: 'Compass ', ...payload }, options ) + console.log('resend.emails.send', data, error) if (error) { log.error( @@ -35,6 +37,7 @@ const getResend = () => { if (resend) return resend const apiKey = process.env.RESEND_KEY as string + console.log(`RESEND_KEY: ${apiKey}`) resend = new Resend(apiKey) return resend } diff --git a/backend/email/emails/new-endorsement.tsx b/backend/email/emails/new-endorsement.tsx index 9ab58793..9c07c923 100644 --- a/backend/email/emails/new-endorsement.tsx +++ b/backend/email/emails/new-endorsement.tsx @@ -44,7 +44,7 @@ export const NewEndorsementEmail = ({ src="https://manifold.love/manifold-love-banner.png" width="550" height="auto" - alt="manifold.love" + alt="compassmeet.com" /> @@ -95,7 +95,7 @@ NewEndorsementEmail.PreviewProps = { onUser: sinclairUser, endorsementText: "Sinclair is someone you want to have around because she injects creativity and humor into every conversation, and her laugh is infectious! Not to mention that she's a great employee, treats everyone with respect, and is even-tempered.", - unsubscribeUrl: 'https://manifold.love/unsubscribe', + unsubscribeUrl: 'https://compassmeet.com/unsubscribe', } as NewEndorsementEmailProps const main = { diff --git a/backend/email/emails/new-match.tsx b/backend/email/emails/new-match.tsx index d385a760..3fb2a737 100644 --- a/backend/email/emails/new-match.tsx +++ b/backend/email/emails/new-match.tsx @@ -44,7 +44,7 @@ export const NewMatchEmail = ({ src="https://manifold.love/manifold-love-banner.png" width="550" height="auto" - alt="manifold.love" + alt="compassmeet.com" /> @@ -91,7 +91,7 @@ NewMatchEmail.PreviewProps = { onUser: sinclairUser, matchedWithUser: jamesUser, matchedLover: jamesLover, - unsubscribeUrl: 'https://manifold.love/unsubscribe', + unsubscribeUrl: 'https://compassmeet.com/unsubscribe', } as NewMatchEmailProps const main = { diff --git a/backend/email/emails/new-message.tsx b/backend/email/emails/new-message.tsx index 3ec643f7..e96bdd2a 100644 --- a/backend/email/emails/new-message.tsx +++ b/backend/email/emails/new-message.tsx @@ -52,7 +52,7 @@ export const NewMessageEmail = ({ src="https://manifold.love/manifold-love-banner.png" width="550" height="auto" - alt="manifold.love" + alt="compassmeet.com" /> diff --git a/backend/email/readme.md b/backend/email/readme.md index fc875bfa..1a48caf0 100644 --- a/backend/email/readme.md +++ b/backend/email/readme.md @@ -21,7 +21,3 @@ yarn dev ``` Open [localhost:3000](http://localhost:3000) with your browser to see the result. - -## License - -MIT License