
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.
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.
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.Files for this step
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.
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.
Common mistake
Displaying “Delivered” immediately after a successful API call.
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
Try it yourself
Did the project start, and which configuration step is complete or still blocked?
Discuss your answer with the lesson tutor
Show a worked solution
Example setup record: The local proxy started and printed the application URL. The private environment contains my verified sender, controlled recipient, provider key and separately generated lab code. Only that lab code goes in the form. If the app reports Mail not configured, the private sender/key/recipient setup is still incomplete.
- Reports whether the complete server-backed project started at its printed URL.
- Distinguishes the private provider key/fixed recipient from the form’s separate practice code.
Files for this step
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.
Common mistake
Assuming a value is secret because the page does not display it.
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.
Try it yourself
What did the page, provider and inbox each show for your attempt?
Discuss your answer with the lesson tutor
Show a worked solution
Example attempt record: The page reported provider acceptance with a reference. The matching provider event exists. My controlled inbox contains Workshop confirmation with “Hello Alex. Your practice request was received.” If the inbox copy were missing, I would record accepted but delivery unresolved.
- Matches the page response, provider event and actual inbox result for the same attempt.
- Identifies a failed stage without turning an error or accepted ID into a delivery claim.
Files for this step
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.
Common mistake
Testing a backend by opening only its HTML file.
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.
Try it yourself
Which observed delivery state explains the next action for your test?
Discuss your answer with the lesson tutor
Show a worked solution
Example diagnosis: The provider accepted the attempt, but its event now reports a bounce and the controlled inbox has no copy. I will inspect the configured destination and that delivery event before another send. This is different from a rejected practice code, which should never reach the mail provider.
- Uses the matching provider status and destination/inbox checks to diagnose the current delivery state.
- Chooses a next action at the observed failed stage instead of blindly repeating sends.
Files for this step
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.
Common mistake
Debugging HTML when the request reached the provider and failed later.
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.
Try it yourself
Start with these materials
The starter files and test content are supplied. A live verification still requires your own permitted provider account, inbox or domain as listed under prerequisites. Local inspection is possible without them; record the live step as not tested until you actually perform it.
Provide your topic change and the actual successful and rejected test results.
What to produce The working test action and a redacted provider/inbox/error record.
Discuss your answer with the lesson tutor
Show a worked solution
Example extension record: Project produced “Hello Alex. Your project request was received.” Question produced the matching question text in a separate controlled email. The unsupported topic other and an incorrect practice code were rejected with no matching provider send. Both allowed choices still use the fixed configured recipient.
- Adds exactly the Project/Question choices and verifies the selected value in actual received content.
- Checks that an unsupported topic and wrong practice code send no message.
Files for this step
Open or download the files below. When saving a project, keep the folder paths shown in the filenames.
- netlify/functions/mini-mail.mjsDownload this file
- delivery-record.txtDownload this file
- worksheet.htmlDownload this file
- reference/assignment-walkthrough.txtDownload this file
- reference/START-HERE.txtDownload this file
- reference/public/index.htmlDownload this file
- reference/public/app.jsDownload this file
- reference/netlify/functions/mini-mail.mjsDownload this file
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.
Common mistake
Trusting a select control as the only validation boundary.
Was this lesson useful?
Leave a like, or share it with someone who could use it.
Continue learning
- How to build your first personal website
- How to publish your website from GitHub
- How to connect a custom domain to your website
- How to set up email on your own domain
- How to make your website usable on phones
- How to make website images load faster
- How to get website feedback in your inbox
- How to add email subscriptions to your website
- How to save form submissions in a database
- How to let people sign in to your website
- How to keep a page private
- How to let users edit their profile information
- How to let users upload images
- How to keep API keys out of your frontend
- How to show data from an external API on your website
- How to add an AI chatbot to your website
- How to make a chatbot answer from your own content
- How to add a blog to your website
- How to add search to your website
- How to add another language to your website
- How to help Google find your website
- How to fix your website preview when sharing a link
- How to measure visits and useful actions on your website
- How to let visitors book an appointment
- How to accept a payment on your website
- How to preview website changes before publishing
- How to undo a broken website deployment
- How to back up and restore your website data
- How to find and fix errors on your live website