Follow the link below to confirm this email address and finish signing up.
`, recovery: `We received a request to reset your password. Follow the link below to choose a new one.
If you didn't request this, you can safely ignore this email.
`, invite: `You've been invited to create an account. Follow the link below to accept.
`, magiclink: `Follow the link below to sign in. This link expires shortly and can only be used once.
`, email_change: `Follow the link below to confirm {{new_email}} as your new email address.
If you didn't request this change, you can safely ignore this email.
`, email_change_new: `Follow the link below to confirm {{new_email}} as your new email address.
If you didn't request this change, you can safely ignore this email.
`, reauthentication: `Use the code below to verify your identity. It expires shortly.
{{token}}
`, }, es: { signup: `Sigue el enlace de abajo para confirmar esta dirección de correo electrónico y terminar el registro.
Confirmar dirección de correo electrónico
`, recovery: `Recibimos una solicitud para restablecer tu contraseña. Sigue el enlace de abajo para elegir una nueva.
Si no solicitaste esto, puedes ignorar este correo.
`, invite: `Te han invitado a crear una cuenta. Sigue el enlace de abajo para aceptar.
`, magiclink: `Sigue el enlace de abajo para iniciar sesión. Este enlace caduca pronto y solo se puede usar una vez.
`, email_change: `Sigue el enlace de abajo para confirmar {{new_email}} como tu nueva dirección de correo electrónico.
Confirmar nueva dirección de correo electrónico
Si no solicitaste este cambio, puedes ignorar este correo.
`, email_change_new: `Sigue el enlace de abajo para confirmar {{new_email}} como tu nueva dirección de correo electrónico.
Confirmar nueva dirección de correo electrónico
Si no solicitaste este cambio, puedes ignorar este correo.
`, reauthentication: `Usa el código de abajo para verificar tu identidad. Caduca pronto.
{{token}}
`, }, fr: { signup: `Suivez le lien ci-dessous pour confirmer cette adresse e-mail et terminer votre inscription.
`, recovery: `Nous avons reçu une demande de réinitialisation de votre mot de passe. Suivez le lien ci-dessous pour en choisir un nouveau.
Si vous n'avez pas fait cette demande, vous pouvez ignorer cet e-mail.
`, invite: `Vous avez été invité à créer un compte. Suivez le lien ci-dessous pour accepter.
`, magiclink: `Suivez le lien ci-dessous pour vous connecter. Ce lien expire bientôt et ne peut être utilisé qu'une seule fois.
`, email_change: `Suivez le lien ci-dessous pour confirmer {{new_email}} comme nouvelle adresse e-mail.
Confirmer la nouvelle adresse e-mail
Si vous n'avez pas demandé ce changement, vous pouvez ignorer cet e-mail.
`, email_change_new: `Suivez le lien ci-dessous pour confirmer {{new_email}} comme nouvelle adresse e-mail.
Confirmer la nouvelle adresse e-mail
Si vous n'avez pas demandé ce changement, vous pouvez ignorer cet e-mail.
`, reauthentication: `Utilisez le code ci-dessous pour vérifier votre identité. Il expire bientôt.
{{token}}
`, }, } function generateConfirmationURL(email_data) { const baseUrl = `https://${PROJECT_REF}.supabase.co/auth/v1/verify` const params = new URLSearchParams({ token: email_data.token_hash, type: email_data.email_action_type, redirect_to: email_data.redirect_to, }) return `${baseUrl}?${params.toString()}` } Deno.serve(async (req) => { const payload = await req.text() const serverToken = Deno.env.get('POSTMARK_SERVER_TOKEN') const headers = Object.fromEntries(req.headers) const base64_secret = Deno.env.get('SEND_EMAIL_HOOK_SECRET').replace('v1,whsec_', '') const wh = new Webhook(base64_secret) const { user, email_data } = wh.verify(payload, headers) const language = (user.user_metadata && user.user_metadata.i18n) || 'en' const subject = subjects[language][email_data.email_action_type] || 'Notification' let template = templates[language][email_data.email_action_type] const confirmation_url = generateConfirmationURL(email_data) let htmlBody = template .replace('{{confirmation_url}}', confirmation_url) .replace('{{token}}', email_data.token || '') .replace('{{new_token}}', email_data.new_token || '') .replace('{{site_url}}', email_data.site_url || '') .replace('{{old_email}}', email_data.old_email || '') .replace('{{new_email}}', user.new_email || '') const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-Postmark-Server-Token': serverToken, }, body: JSON.stringify({ From: FROM_EMAIL, To: user.email, Subject: subject, HtmlBody: htmlBody, }), } try { const response = await fetch(postmarkEndpoint, requestOptions) if (!response.ok) { const errorData = await response.json() throw new Error(`Failed to send email: ${errorData.Message}`) } return new Response( JSON.stringify({ message: 'Email sent successfully.', }), { headers: { 'Content-Type': 'application/json', }, } ) } catch (error) { return new Response( JSON.stringify({ error: `Failed to process the request: ${error.message}`, }), { status: 500, headers: { 'Content-Type': 'application/json', }, } ) } }) ```Follow the link below to confirm this email address and finish signing up.
`, recovery: `We received a request to reset your password. Follow the link below to choose a new one.
If you didn't request this, you can safely ignore this email.
`, invite: `You've been invited to create an account. Follow the link below to accept.
`, magiclink: `Follow the link below to sign in. This link expires shortly and can only be used once.
`, email_change: `Follow the link below to confirm {{new_email}} as your new email address.
If you didn't request this change, you can safely ignore this email.
`, email_change_new: `Follow the link below to confirm {{new_email}} as your new email address.
If you didn't request this change, you can safely ignore this email.
`, reauthentication: `Use the code below to verify your identity. It expires shortly.
{{token}}
` }; function generateConfirmationURL(email_data) { // TODO: replace the ref with your project ref return `https://.supabase.co/auth/v1/verify?token=${email_data.token_hash}&type=${email_data.email_action_type}&redirect_to=${email_data.redirect_to}` } async function sendEmailWithPostmark(user: any, email_data: any, serverToken: string): Promise