DEV Community

Julia for Light Cloud

Posted on Originally published at blog.light-cloud.com on

SaaS Part 2: Send Sign-up Emails With Resend

SaaS Part 2: Send Sign-up Emails With Resend

To send sign-up emails from a SaaS on Light Cloud, verify your domain in Resend, create an API key, and add two environment variables to the app: RESEND_API_KEY and EMAIL_FROM. Saving redeploys the app, and from then on verification, password reset and invitation emails reach real inboxes. New accounts must confirm their email address before they can sign in.

What you will build

The app from part 1, now sending its own emails:

  • Confirm your email , sent after sign-up;
  • Reset your password , from the Forgot password page;
  • Invitations , when you invite a teammate to a workspace;
  • Welcome , sent with the verification email when an account is created.

    Before you start

  • The app from part 1, running.

  • A Resend account. The free plan is enough for this tutorial. <!-- VERIFY: the free plan limits on resend.com/pricing on the run date -->

  • A domain you can add DNS records to. I used example.com, a stand-in for yours: wherever you see it, type your own domain. A subdomain is fine too, and it keeps the records away from your main domain's email.

Step 1: Add the domain to Resend

  1. In Resend, open Domains and click Add Domain.
  2. Enter the domain, here example.com, and pick the region closest to your users. <!-- VERIFY: region list and the one picked -->
  3. Resend shows the DNS records to add. <!-- IMAGE: s2-01-resend-records.webp, the Resend DNS records table (light + dark if Resend has a dark theme) --> ## Step 2: Add the DNS records

At your DNS provider, add each record exactly as Resend shows it:

Type Name Value
MX send feedback-smtp.....amazonses.com
TXT send v=spf1 include:amazonses.com ~all
TXT resend._domainkey p=MIGfMA0...

Back in Resend, click Verify DNS Records. The domain shows Verified once the records are found. <!-- VERIFY: "In my run that took N minutes." -->

You can check a record yourself from the terminal:

$ nslookup -type=TXT resend._domainkey.example.com
VERIFY: trimmed real output


PS> nslookup -type=TXT resend._domainkey.example.com
VERIFY: trimmed real output

Enter fullscreen mode Exit fullscreen mode

Step 3: Create an API key

In Resend, open API Keys , click Create API Key , name it saas-production, and give it Sending access to your domain only. Copy the key. It starts with re_ and Resend shows it only once.

Step 4: Add the variables to the app

  1. In the Light Cloud console, open the app, then Production , Settings , and click Edit next to Environment Variables.
  2. Add two variables:
Name Value
RESEND_API_KEY the key from step 3
EMAIL_FROM Rota Planner <hello@example.com>
  1. Click Save.

The Production editor with EMAIL_FROM changed to Rota Planner hello@example.com and a new row RESEND_API_KEY with its value hidden, Save highlighted

The key in my screenshots is a fake sample. Yours starts with re_ too.

EMAIL_FROM is the sender people see. The part in angle brackets must be an address on the domain you verified. The name before it can be anything.

Saving deploys the app again. <!-- VERIFY: "In my run it was live N seconds later." -->

Step 5: Sign up with a new address

Open the app in a private window and sign up with an email address you can read. Instead of the dashboard, you now see a page asking you to confirm your email:

Open the email and click the link. You're signed in and go on to onboarding.

If the email doesn't arrive, open Emails in Resend. Every email the app sent is listed there, with its status.

Step 6: Try a password reset

Sign out, click Forgot password on the sign-in page, and enter the same address. The email says the link works for one hour. Open it, choose a new password, and sign in with it.

Troubleshooting

Open the app's Logs tab first. A failed email logs a line that starts with Email to.

Email to ... failed: The ... domain is not verified

EMAIL_FROM uses an address on a domain that Resend hasn't verified yet. Wait for Verified in Resend, or fix the address. <!-- VERIFY: exact Resend error text -->

Email to ... failed: API key is invalid

The key was copied incompletely, or it was deleted in Resend. Create a new key and replace RESEND_API_KEY.

The email arrives in spam

New domains have no sending history yet. Add a DMARC record (_dmarc, TXT, v=DMARC1; p=none;), send a few emails to yourself and mark them as not spam.

Emails still show up in the logs instead of being sent

The app reads its variables when it starts. Check that RESEND_API_KEY is set on the Production environment and that the deploy after saving finished.

Top comments (0)