Add email sending

This commit is contained in:
MartinBraquet
2025-08-28 12:49:05 +02:00
parent b707439de7
commit 7572d1a6ff
7 changed files with 33 additions and 15 deletions

View File

@@ -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)
}

View File

@@ -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 <no-reply@poly.love>'
const from = 'Compass <no-reply@compassmeet.com>'
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(
<NewMessageEmail
fromUser={fromUser}
fromUserLover={lover}
toUser={toUser}
channelId={channelId}
unsubscribeUrl={unsubscribeUrl}
/>
),
})
return await sendEmail({
from,
subject: `${fromUser.name} sent you a message!`,
to: privateUser.email,
react: (
html: renderToStaticMarkup(
<NewMessageEmail
fromUser={fromUser}
fromUserLover={lover}
@@ -101,8 +117,8 @@ export const sendNewEndorsementEmail = async (
export const sendTestEmail = async (toEmail: string) => {
return await sendEmail({
from,
subject: 'Test email from Love',
subject: 'Test email from Compass',
to: toEmail,
react: <Test name="Test User" />,
html: renderToStaticMarkup(<Test name="Test User" />),
})
}

View File

@@ -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 <no-reply@compassmeet.com>', ...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
}

View File

@@ -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"
/>
</Section>
@@ -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 = {

View File

@@ -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"
/>
</Section>
@@ -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 = {

View File

@@ -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"
/>
</Section>

View File

@@ -21,7 +21,3 @@ yarn dev
```
Open [localhost:3000](http://localhost:3000) with your browser to see the result.
## License
MIT License