Skip to content

Production sends no email: SENDGRID_API_KEY is not set #431

Closed

Description

@thinkclay

What

There is no mail provider configured in the production Supabase edge function secrets. Listing them returns:

DEPLOYED_AT, EXPO_PUBLIC_URL, GIT_COMMIT, INBOUND_EMAIL_BASE_DOMAIN,
OPENAI_API_KEY, SUPABASE_ANON_KEY, SUPABASE_DB_URL, SUPABASE_JWKS,
SUPABASE_PUBLISHABLE_KEYS, SUPABASE_SECRET_KEYS, SUPABASE_SERVICE_ROLE_KEY,
SUPABASE_URL, TEAM_APP_BASE_URL

No SENDGRID_API_KEY.

Impact

packages/supabase/functions/_shared/notifications/adapters/email.ts returns error: 'SENDGRID_API_KEY environment variable is not set' and sends nothing. Every email channel notification is silently dropped in production — background check status and expiry reminders, ID verification, community notifications, team invitations. The new contact form on the marketing page returns 503 for the same reason.

This was found while migrating the contact endpoint off Resend (#430); it is not caused by that change, which only made an existing gap visible.

Fix

  1. Set the key on the edge functions:
    supabase secrets set SENDGRID_API_KEY=... --project-ref qmfmpcyxsihhfttvqpbw
    
  2. Set the same key in the EAS Hosting production environment, which is where the contact endpoint runs — the two are separate runtimes and do not share secrets.
  3. Add SendGrid to SPF at the same time. scaffald.com currently publishes v=spf1 include:_spf.google.com ~all, which authorizes Google Workspace only. Mail sent from [email protected] through SendGrid will softfail SPF and land in spam. The record needs include:sendgrid.net.
  4. Verify the [email protected] sender is verified on the SendGrid account.

Do steps 1 and 3 together — turning on sending without the SPF include trains recipients to treat our mail as spam, which is harder to undo than it is to avoid.

Then

Once the sender list is known to be complete (Google Workspace + SendGrid), SPF can be tightened from ~all back to -all. It was loosened deliberately on 2026-07-28 on Google Workspace's advice, because -all with an incomplete list was hard-failing legitimate mail.

Activity

  1. added
    bug
    on Jul 29, 2026
  2. thinkclay commented on Jul 29, 2026

    @thinkclay
    ContributorAuthor

    Resolved by moving all outbound mail to Resend rather than funding SendGrid — 83c7a33f6.

    Done:

    • scaffald.com claimed and verified in the unicorn Resend team, us-east-1. It was held by another Resend team; ownership was transferred, which revoked that team's access.
    • DNS published in Route53: DKIM at resend._domainkey, plus SPF and MX on send.scaffald.com.
    • All three senders ported — the notification adapter, send-team-invitation (which had its own copy of the SendGrid call), and the contact form.
    • Delivery webhook rewritten for Resend's event shape, and it now verifies the Svix signature. The SendGrid version accepted delivery statuses from anyone who found the URL.

    The SPF concern in the original report does not apply. Resend sets the envelope sender to send.scaffald.com, so SPF is evaluated there and DMARC aligns to the apex through DKIM. The apex record keeps include:_spf.google.com ~all unchanged — widening it would have been wrong.

    Remaining — needs the API key, which has to be installed by a human:

    echo 'RESEND_API_KEY=re_...' >> .env
    npx supabase secrets set RESEND_API_KEY=re_... --project-ref qmfmpcyxsihhfttvqpbw
    cd apps/scaffald && npx eas-cli@latest env:create --scope project \
      --name RESEND_API_KEY --value re_... --type secret --environment production

    Three separate runtimes, no shared secrets. EAS Hosting reads env at deploy time, so the contact form needs a redeploy after step three.

    Optionally RESEND_WEBHOOK_SECRET from https://resend.com/webhooks — until it is set the webhook rejects every event, so delivery tracking stays dark (mail still sends).

    Full runbook: docs/setup/RESEND.md

  3. thinkclay commented on Jul 29, 2026

    @thinkclay
    ContributorAuthor

    API key created and verified working. Confirmed against the live API:

    • key has domain access; scaffald.com reads status=verified, region=us-east-1
    • a real send from [email protected] reached last_event: delivered (id 31cc2676-…)
    • the contact endpoint itself returns 200 {"ok":true} end to end against Resend, exercising the real POST handler

    So the transport is proven. Sending is not the remaining problem — deployment is, see #436: only 6 of the repo's 26 edge functions run in production, and notify-send-worker (the only function that actually dispatches a notification) is not one of them. core.notification_deliveries is empty.

    That means the Supabase secret is correct to set but pre-positions the credential rather than fixing anything today. The step that produces a working feature right now is the EAS one, since the contact form runs on EAS Hosting and never touches Supabase.

  4. thinkclay commented on Jul 30, 2026

    @thinkclay
    ContributorAuthor

    Resolved and verified end to end in production.

    Key installed in all three runtimes:

    • .env (local) — used for the verified test sends
    • Supabase edge function secrets — digest matches the known-good key
    • EAS Hosting — all three environments, --visibility sensitive

    Live verification (2026-07-30):

    • POST https://scaffald.com/api/contact → 200 {"ok":true} (also direct to the EAS origin, ruling out CloudFront)
    • Both messages reached last_event: delivered in Resend — From Scaffald <[email protected]>, To [email protected], reply-to set to the submitter

    Two deploy-time traps found on the way, both fixed in af85a9a5c and documented in docs/setup/RESEND.md:

    1. --visibility secret is only decryptable inside the EAS build environment — the Hosting worker gets nothing and the route 503s while the deploy reports success. Server-side vars must be sensitive. A secret var can't be downgraded in place; delete and re-set.
    2. eas deploy --prod does not load environment variables — --prod picks the URL, --environment production picks the vars. The CI workflow had the same bug and would have shipped every future worker with no server config.

    scripts/set-resend-eas-env.sh now does the EAS half idempotently with validation.

    What this does not fix: notification email. The senders aren't deployed — notify-send-worker and the rest of the pipeline are absent from production. That's #436.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions