Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: send emails on contact form submissions

Alaister Young1fcc70e1858c
diff --git a/.gitignore b/.gitignore
index e5840f62fad..6364efb6add 100644
--- a/.gitignore
+++ b/.gitignore
@@ -106,3 +106,7 @@ typings/
!docker/.env
!docker/supabase/.env
!docker/supabase-traefik/.env
+
+# Supabase
+**/supabase/.branches
+**/supabase/.temp
diff --git a/www/components/EnterpriseContactForm.tsx b/www/components/EnterpriseContactForm.tsx
index e817c39e265..af4c80eda3a 100644
--- a/www/components/EnterpriseContactForm.tsx
+++ b/www/components/EnterpriseContactForm.tsx
@@ -122,7 +122,9 @@ const EnterpriseContactForm = () => {
<div>
<Select label="Country / Main Timezone" id="country" name="country" layout="vertical">
{countries.map(({ code, name }) => (
- <Select.Option value={code}>{name}</Select.Option>
+ <Select.Option key={code} value={code}>
+ {name}
+ </Select.Option>
))}
</Select>
</div>
diff --git a/www/next.config.js b/www/next.config.js
index 291212b011d..b0be5c9eee3 100644
--- a/www/next.config.js
+++ b/www/next.config.js
@@ -2,7 +2,7 @@ const withMDX = require('@next/mdx')()
module.exports = withMDX({
basePath: '',
- pageExtensions: ['js', 'jsx', 'tsx', 'md', 'mdx'],
+ pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx'],
trailingSlash: false,
images: {
diff --git a/www/package-lock.json b/www/package-lock.json
index 6d2dcf5df75..f4d150e8c34 100644
--- a/www/package-lock.json
+++ b/www/package-lock.json
@@ -25,6 +25,7 @@
"next": "latest",
"next-mdx-remote": "^2.1.3",
"next-seo": "^4.20.0",
+ "nodemailer": "^6.7.3",
"react": "^17.0.2",
"react-copy-to-clipboard": "^5.0.2",
"react-dom": "^17.0.2",
@@ -49,6 +50,7 @@
"@types/jest": "^25.2.2",
"@types/marked": "^4.0.3",
"@types/node": "^14.0.1",
+ "@types/nodemailer": "^6.4.4",
"@types/react": "^16.9.35",
"@types/react-copy-to-clipboard": "^4.3.0",
"@types/react-dom": "^16.9.8",
@@ -2809,6 +2811,15 @@
"integrity": "sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A==",
"dev": true
},
+ "node_modules/@types/nodemailer": {
+ "version": "6.4.4",
+ "resolved": "https://registry.npmjs.org/@types/nodemailer/-/nodemailer-6.4.4.tgz",
+ "integrity": "sha512-Ksw4t7iliXeYGvIQcSIgWQ5BLuC/mljIEbjf615svhZL10PE9t+ei8O9gDaD3FPCasUJn9KTLwz2JFJyiiyuqw==",
+ "dev": true,
+ "dependencies": {
+ "@types/node": "*"
+ }
+ },
"node_modules/@types/parse-json": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz",
@@ -5811,6 +5822,14 @@
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.2.tgz",
"integrity": "sha512-XxYDdcQ6eKqp/YjI+tb2C5WM2LgjnZrfYg4vgQt49EK268b6gYCHsBLrK2qvJo4FmCtqmKezb0WZFK4fkrZNsg=="
},
+ "node_modules/nodemailer": {
+ "version": "6.7.3",
+ "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.3.tgz",
+ "integrity": "sha512-KUdDsspqx89sD4UUyUKzdlUOper3hRkDVkrKh/89G+d9WKsU5ox51NWS4tB1XR5dPUdR4SP0E3molyEfOvSa3g==",
+ "engines": {
+ "node": ">=6.0.0"
+ }
+ },
"node_modules/normalize-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
@@ -11117,6 +11136,15 @@
"integrity": "sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A==",
"dev": true
},
+ "@types/nodemailer": {
+ "version": "6.4.4",
+ "resolved": "https://registry.npmjs.org/@types/nodemailer/-/nodemailer-6.4.4.tgz",
+ "integrity": "sha512-Ksw4t7iliXeYGvIQcSIgWQ5BLuC/mljIEbjf615svhZL10PE9t+ei8O9gDaD3FPCasUJn9KTLwz2JFJyiiyuqw==",
+ "dev": true,
+ "requires": {
+ "@types/node": "*"
+ }
+ },
"@types/parse-json": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz",
@@ -13310,6 +13338,11 @@
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.2.tgz",
"integrity": "sha512-XxYDdcQ6eKqp/YjI+tb2C5WM2LgjnZrfYg4vgQt49EK268b6gYCHsBLrK2qvJo4FmCtqmKezb0WZFK4fkrZNsg=="
},
+ "nodemailer": {
+ "version": "6.7.3",
+ "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.3.tgz",
+ "integrity": "sha512-KUdDsspqx89sD4UUyUKzdlUOper3hRkDVkrKh/89G+d9WKsU5ox51NWS4tB1XR5dPUdR4SP0E3molyEfOvSa3g=="
+ },
"normalize-path": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
diff --git a/www/package.json b/www/package.json
index ac72cf9ccd5..3df5eb9d571 100644
--- a/www/package.json
+++ b/www/package.json
@@ -29,6 +29,7 @@
"next": "latest",
"next-mdx-remote": "^2.1.3",
"next-seo": "^4.20.0",
+ "nodemailer": "^6.7.3",
"react": "^17.0.2",
"react-copy-to-clipboard": "^5.0.2",
"react-dom": "^17.0.2",
@@ -53,6 +54,7 @@
"@types/jest": "^25.2.2",
"@types/marked": "^4.0.3",
"@types/node": "^14.0.1",
+ "@types/nodemailer": "^6.4.4",
"@types/react": "^16.9.35",
"@types/react-copy-to-clipboard": "^4.3.0",
"@types/react-dom": "^16.9.8",
diff --git a/www/supabase/config.toml b/www/supabase/config.toml
new file mode 100644
index 00000000000..cc86c099e31
--- /dev/null
+++ b/www/supabase/config.toml
@@ -0,0 +1,60 @@
+# A string used to distinguish different Supabase projects on the same host. Defaults to the working
+# directory name when running `supabase init`.
+project_id = "obuldanrptloktxcffvn"
+
+[api]
+# Port to use for the API URL.
+port = 54321
+# Schemas to expose in your API. Tables, views and stored procedures in this schema will get API
+# endpoints. public and storage are always included.
+schemas = []
+# Extra schemas to add to the search_path of every request.
+extra_search_path = ["extensions"]
+# The maximum number of rows returns from a view, table, or stored procedure. Limits payload size
+# for accidental or malicious requests.
+max_rows = 1000
+
+[db]
+# Port to use for the local database URL.
+port = 54322
+# The database major version to use. This has to be the same as your remote database's. Run `SHOW
+# server_version;` on the remote database to check.
+major_version = 14
+
+[studio]
+# Port to use for Supabase Studio.
+port = 54323
+
+# Email testing server. Emails sent with the local dev setup are not actually sent - rather, they
+# are monitored, and you can view the emails that would have been sent from the web interface.
+[inbucket]
+# Port to use for the email testing server web interface.
+port = 54324
+
+[auth]
+# The base URL of your website. Used as an allow-list for redirects and for constructing URLs used
+# in emails.
+site_url = "http://localhost:3000"
+# A list of *exact* URLs that auth providers are permitted to redirect to post authentication.
+additional_redirect_urls = ["https://localhost:3000"]
+# How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 seconds (one
+# week).
+jwt_expiry = 3600
+# Allow/disallow new user signups to your project.
+enable_signup = true
+
+[auth.email]
+# Allow/disallow new user signups via email to your project.
+enable_signup = true
+# If enabled, a user will be required to confirm any email change on both the old, and new email
+# addresses. If disabled, only the new email is required to confirm.
+double_confirm_changes = true
+# If enabled, users need to confirm their email address before signing in.
+enable_confirmations = true
+
+# Use an external OAuth provider. The full list of providers are: `apple`, `azure`, `bitbucket`,
+# `discord`, `facebook`, `github`, `gitlab`, `google`, `twitch`, `twitter`, `slack`, `spotify`.
+[auth.external.apple]
+enabled = false
+client_id = ""
+secret = ""
diff --git a/www/supabase/functions/contact-notification/index.ts b/www/supabase/functions/contact-notification/index.ts
new file mode 100644
index 00000000000..4c2463496de
--- /dev/null
+++ b/www/supabase/functions/contact-notification/index.ts
@@ -0,0 +1,62 @@
+import { serve } from 'https://deno.land/[email protected]/http/server.ts'
+import { SmtpClient } from 'https://deno.land/x/[email protected]/mod.ts'
+
+const smtp = new SmtpClient()
+
+serve(async (req) => {
+ await smtp.connect({
+ hostname: Deno.env.get('SMTP_HOSTNAME')!,
+ port: Number(Deno.env.get('SMTP_PORT')!),
+ username: Deno.env.get('SMTP_USERNAME')!,
+ password: Deno.env.get('SMTP_PASSWORD')!,
+ })
+
+ const body = await req.json()
+
+ const functionSecret = Deno.env.get('FUNCTION_SECRET')
+ const requestSecret = req.headers.get('x-function-secret')
+
+ if (functionSecret !== requestSecret) {
+ return new Response('Unauthorized', { status: 401 })
+ }
+
+ const { table, record } = body
+
+ const content = Object.entries(record).reduce(
+ (acc, [key, value]) => acc + `${key}: ${value || 'NOT_PROVIDED'}\n`,
+ ''
+ )
+
+ let to = Deno.env.get('SMTP_FALLBACK_TO')!
+ let form = 'Unknown'
+
+ if (table === 'enterprise_contacts') {
+ to = Deno.env.get('SMTP_ENTERPRISE_TO')!
+ form = 'Enterprise'
+ } else if (table === 'partner_contacts') {
+ to = Deno.env.get('SMTP_PARTNER_TO')!
+ form = 'Partner'
+ }
+
+ try {
+ await smtp.send({
+ from: Deno.env.get('SMTP_FROM')!,
+ to,
+ subject: `New Contact Form Submission (${form})`,
+ content,
+ })
+ } catch (error: any) {
+ return new Response(error.message, { status: 500 })
+ }
+
+ await smtp.close()
+
+ return new Response(
+ JSON.stringify({
+ done: true,
+ }),
+ {
+ headers: { 'Content-Type': 'application/json' },
+ }
+ )
+})