Mini lesson · English

How to send automated emails from your website

Run a supplied email project with an assistant, send a controlled confirmation and verify its arrival in your inbox.

Start the interactive lessonRead the lesson below

Who is this for?

People who want a website action to trigger an email. The server code is supplied and a coding assistant can configure it; you do not need to write an email backend.

Before you start

Your own Resend account, a verified sender and a test inbox. Use the complete separate Netlify-function project and a coding assistant for setup. Provider availability and usage terms apply. Worked answers are illustrative examples, not completed tests on your account. Replace their sample observations with your own results, or identify the step that is still blocked.

Estimated time: 21–38 min

Estimates for the supplied starter files with prerequisite accounts and tools ready. Setup, deployment queues and delivery/DNS waits take additional time. Sender verification and mail delivery waits are additional. Provider fees/limits depend on the account.

What you will learn

  • Configure a controlled sender and recipient.
  • Trigger a real test email and inspect delivery.
  • Handle failed requests without pretending a message arrived.

Workshop files

Step 1

Choose one email action

Start with a fixed, controlled confirmation.

Open the supplied project with your assistant and decide what event should send the test confirmation. Use only the configured owner inbox; the visitor should not choose arbitrary recipients.

Distinguish a request being accepted by the provider from a message arriving in the inbox.

A concrete example

The supplied action sends a fixed Workshop confirmation to the server-configured recipient. The form visitor supplies a name, not an arbitrary destination. A returned message reference helps trace it but does not establish arrival.

Open this complete email workshop. Follow run-locally.txt and explain the private sender, recipient, provider key and practice-code values. Keep them out of public files. Help run the project and trigger only my own configured test inbox. Inspect provider acceptance and actual inbox delivery separately, including a rejected attempt.

Resend: sending email

Files for this step

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Send an email after a website action

A server function turns an accepted request into a mail-provider call.

The browser should request a specific action, not hold your privileged email credential. In this lab, it submits a name to a server function, which sends a plain-text confirmation to your own configured inbox.

Resend is the worked route. A different transactional provider can serve the same role, but its authentication, sender verification and delivery events differ. A human mailbox is a separate service.

Worked example

The response “accepted” means the provider accepted the send request. It is not proof that an inbox received the message. We will check that boundary separately.

Resend: sending email

Extra implementation exercise

The provider returned a message ID, but you have not checked the inbox. What can you honestly claim?

Show a worked solution

The provider accepted a request with that reference. Delivery remains unverified until you inspect delivery evidence and the test inbox.

  • Claims acceptance, not confirmed inbox delivery.
  • Keeps a message reference for the delivery check.

Step 2

Configure and start the ready project

Let the assistant handle the server wiring.

Follow run-locally.txt with your assistant. Enter the account’s private values using server-env.example.txt, then start the complete project and open its real local URL.

Keep the provider key and fixed recipient on the server. The form’s practice code is separate from the provider key; a file preview does not run the email service.

A concrete example

Server values choose the sender, recipient and provider access. The separate practice code permits this owner-only test. Neither a hidden browser field nor a plain file preview performs that private server setup.

Node.js: supported release status

Files for this step

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Configure one restricted practice sender

Keep sender credentials and the test recipient outside the public folder.

Local checklist: confirm Node and npm are installed, install/verify Netlify CLI, then follow run-locally.txt before submitting the form. Opening the static page first is useful for layout, but cannot test its server function.

Read netlify/functions/mini-mail.mjs. Configure its mail environment variables and an unguessable LAB_TOKEN (at least 24 characters) in your own hosting project. MAIL_FROM must be authorized by your provider; TEST_RECIPIENT is your test inbox. Do not put the API key in public/app.js.

The user enters the separate practice access code for this restricted lab; it is never bundled in the page and is not your Resend key. The function deliberately ignores caller-supplied destinations. It validates a small name field and creates plain-text content. Before a public release, add durable request limits and review quotas; the owner-only lab is not a complete abuse-control system.

The destination is deliberately server-owned. A crafted browser request can add to='somewhere-else', but the function constructs its own provider payload and uses TEST_RECIPIENT. This prevents this lab's caller from turning the feature into a sender to arbitrary addresses; public access would still need durable abuse controls.

For the complete local sequence, open run-locally.txt: prepare the private root environment, link only the practice project and start the Netlify function proxy. server-env.example.txt lists variable names without real secrets. Opening only the HTML cannot run the server.

Worked example

An attacker changing a browser request cannot redirect this lab’s email because the recipient comes from the server environment. Hiding an address in JavaScript would not provide that protection.

const {RESEND_API_KEY, MAIL_FROM, TEST_RECIPIENT} = process.env;
// Send only to TEST_RECIPIENT in this lab.

Node.js: supported release status

Extra implementation exercise

Would moving the key into a hidden input keep it private?

Show a worked solution

No. Hidden form inputs are still delivered to the browser. Keep the credential in the server environment and perform the provider call there.

  • Recognizes browser-delivered values are inspectable.
  • Moves privileged use to the server environment.

Step 3

Send one recognizable test

Use the interface and keep the evidence linked.

Trigger the confirmation from the actual running page. Save its test reference and inspect the corresponding provider event and inbox copy.

If the request fails, keep the failure visible and retain enough context to retry. Do not fix an unavailable service by inventing a success message.

A concrete example

For the synthetic name Alex, the starter’s email text is “Hello Alex. Your practice request was received.” Compare the actual received copy with the matching attempt rather than an older email.

Files for this step

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Follow the supplied request and response

The button submits JSON; the server validates it, then returns an honest status.

Deploy the separate project or run it with the host’s local function tooling. Opening index.html as a local file does not run the backend. Submit a synthetic name and inspect the network response.

The server returns 400 for malformed input, 503 for missing configuration, 502 for a failed provider call and 202 when the provider accepts the message. The browser handles failure without pretending the email arrived.

Worked example

The practice UI says “Accepted by the mail provider. Check your test inbox.” That matches what the server knows at that point.

Extra implementation exercise

The endpoint returns 503. Should you start by changing the button’s colour or checking the server environment?

Show a worked solution

Check the configured environment variables and sender setup. The UI’s appearance cannot supply missing server credentials.

  • Checks the missing server configuration first.
  • Does not treat the failed request as a completed email.

Step 4

Investigate a missing message

Look for the delivery state before sending repeatedly.

Use delivery-record.txt to match the test reference to the provider status, destination and inbox/spam check. Ask your assistant for help with the failed stage.

A bounce or rejected destination needs investigation. Repeating the same send blindly can create noise without fixing delivery.

A concrete example

Accepted → bounced → no inbox copy points to delivery investigation. Practice-code rejection → no provider event points to access configuration. These observations lead to different next checks.

Files for this step

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Verify delivery and failure

Connect one click, its provider reference and the actual received message.

Find the accepted message in your provider’s activity and inspect its delivery state. Then check the configured test inbox, including spam. Record acceptance and received-copy observations separately.

Try an empty name through the normal form and malformed JSON through a developer request. In a separate disposable configuration, verify that missing credentials fail cleanly. Never share provider response bodies that might contain account details.

Worked example

A delivery event and a matching received message are stronger evidence than a green button. Provider acceptance without a received copy is an unresolved delivery investigation.

Extra implementation exercise

The provider lists a bounce for the test reference. Is repeating the same send immediately the best next step?

Show a worked solution

Inspect the reported failure and recipient configuration first. Retry only after identifying what changed; repeated identical sends do not repair an invalid destination.

  • Investigates the bounce reason and destination.
  • Avoids repeated requests without a changed diagnosis.

Step 5

Add a useful message topic

Describe the behavior and have the assistant implement it.

Ask the assistant to add two topic choices: Project and Question, with values project and question. Include the selected value in the confirmation body while retaining the fixed server recipient and private key. Have the assistant help test an unsupported value, other, without adding it as an allowed choice.

Send one controlled test per allowed choice and inspect the actual received text. The unsupported topic and a wrong practice code should be rejected without a provider send; check those negative attempts separately.

A concrete example

The task has two allowed choices: Project and Question, stored as project and question. The selected value must reach the email body. Other is an intentionally unsupported test value, not a third option to add.

Files for this step

Start hereWorkshop files

Open or download the files below. When saving a project, keep the folder paths shown in the filenames.

How it works (optional)

Your assignment: add a meaningful confirmation detail

Include a short request topic without allowing arbitrary recipients or HTML.

Add a topic field with two allowed values. Validate the allowlist on the server and include the selected value in the plain-text confirmation. Keep the recipient fixed in the environment.

Send a matching test for each value and one unsupported value. Record the provider reference and actual delivery evidence.

Edit your starter files first. Then compare the topic select, request JSON and server allowlist line by line against the reference files. The reference folder is a complete alternative for checking your work, not another folder to paste blindly into public/.

Worked example

Accepting only “project” and “question” is more reviewable than copying arbitrary caller content into every email field.

The complete reference walkthrough is available in reference/assignment-walkthrough.txt. Compare its steps with your own result; fill the test record from observations in your own project.

Extra implementation exercise

Extend the confirmation with a validated topic and demonstrate successful and rejected requests.

Show a worked solution

The topic extension uses exactly two allowed values, 'project' and 'question'. Add the select to the form, include topic in the JSON and validate that allowlist on the server before calling the mail provider. The reference frontend and function show the complete changes.

Keep TEST_RECIPIENT server-owned even if a crafted request supplies another address. A permitted topic and valid practice code can reach provider acceptance; an unsupported topic must return 400 without a provider call. Acceptance is not an inbox receipt.

Send each allowed topic through your own test account, match its provider reference with the actual received message and record a bounce/pending outcome honestly. The reference code is a restricted lab extension, not a public mail relay.

  • Server rejects unsupported topics and retains the fixed recipient.
  • Both allowed topics appear in matching received messages.

Was this lesson useful?

Leave a like, or share it with someone who could use it.

Continue learning

Explore the other lessons