Send an email from your site
The Send an email task emails you when a visitor writes to you, through your own email service and its key. Your contact form sends the visitor's name, email and message to your site, and the task passes them on to your inbox.
On this page
- What it does
- Add the task
- Keys to add
- Email service address (EMAIL_API_URL), a setting
- Email service key (EMAIL_KEY), a secret
- Sender (EMAIL_FROM), a setting
- Your email address (EMAIL_TO), a setting
- Connect your form
- Try it in the preview
- Go live
- Services it works with as written
- Common problems
- The form answers not_set_up
- Your message couldn't be sent
- It says sent but no email came
- The form gets a length message
What it doesLink to this section
- It answers
/api/contacton your site. A form sends it the visitor's name, email address and message. - It sends one email to your own address, with the subject New message from and the visitor's name. Reply in your email app and your answer goes to the visitor.
- It never emails an address the visitor types, so nobody can use your form to send mail to others.
- It checks the fields first and answers in plain words, like Add your name, Check your email address or Write a message. A name can have up to 100 characters and a message up to 5,000.
- A hidden field named website catches most spam bots: when it has text, the task says sent and sends nothing.
Add the taskLink to this section
In Server tasks (top menu), choose Add a ready-made task, pick Send an email and choose Add task. The setup card lists the four keys below, each with Add key. If your site already has a file answering /api/contact, Xodia names the new one /api/contact-2 and the card uses that name.
Keys to addLink to this section
Add them in this order: when Email service address is saved first, the form for Email service key fills in which service the key is for.
Email service address (EMAIL_API_URL), a settingLink to this section
Find the address
Open your email service's API guide, on the page about sending an email. Copy the full address it sends to, starting with
https://.Add it
Choose Add key next to Email service address, paste the address as the value and save. It is a setting, so you see it after saving.
Email service key (EMAIL_KEY), a secretLink to this section
Make a key
In your email service's dashboard, usually under API keys, make a key that can send email. Give it the least access the service offers, such as sending only.
Add it
Choose Add key next to Email service key and paste it. Under Which service is it for?, check it shows your service's host: the part after
https://in the address, up to the next slash, likeapi.example.com.
Sender (EMAIL_FROM), a settingLink to this section
The sender on each email, like Website <hello@your-domain.example>. It must be an address or domain you verified at your email service, in its sender or domain settings.
Your email address (EMAIL_TO), a settingLink to this section
The inbox every message goes to. Any address you read.
Connect your formLink to this section
Your form sends its fields to /api/contact as JSON with name, email and message, and shows the answer. In the setup card, Connect it with AI asks your AI to do it. Or tell it:
Connect the contact form to / api/ contact: send name, email and message as JSON, add a hidden field named website, and show a thank you line when it answers sent, or its error words when it doesn't.Try it in the previewLink to this section
Turn on server tasks
In the setup card, choose Turn on server tasks if they are off.
Send the form
Fill in the form in the preview with your own email address and send it. The email should reach the address in EMAIL_TO within a minute.
Check the call
In Project settings, Server tasks, Recent calls, pick Preview. A good call shows status 200. If the email didn't come, the call says what the email service answered.
Go liveLink to this section
Publish your site. The live copy of the task starts answering your form on your live address. Send one more message from the live site to be sure.
Services it works with as writtenLink to this section
The task sends the key as a Bearer header and the email as JSON with from, to, subject, text and reply_to. We checked these services' API guides against that shape:
- Resend: Email service address
https://api.resend.com/emails, key from API Keys, sender on a domain you verified.
Many other email services take the key in a header of their own, or the fields under other names. For one of those, change mailRequest() in api/contact.ts to match its guide, or ask your AI to. The rest of the task stays the same.
Common problemsLink to this section
The form answers not_set_upLink to this section
One of the four keys isn't added. Open Keys and secrets and check EMAIL_KEY, EMAIL_API_URL, EMAIL_FROM and EMAIL_TO are all there, spelled exactly so.
Your message couldn't be sentLink to this section
The email service said no, or couldn't be reached. Open the call in Recent calls: what the task wrote shows the service's answer, such as the email service answered 401 with the service's own reason.
- 401 or a line about the key: the key is wrong, or Which service is it for? doesn't match the host in EMAIL_API_URL. Replace the key, or choose Change service on it.
- A line about the sender or the domain: verify that address or domain at your email service, or use one you already verified, in EMAIL_FROM.
- The email service couldn't be reached: check EMAIL_API_URL is the full address from the guide, starting with https://.
- A line about a missing or unknown field: your service names its fields differently. Change mailRequest() to match its guide.
It says sent but no email cameLink to this section
Look in your spam folder first. If the form has a field named website that people can see and fill in, the task treats them as a bot: keep that field hidden.
The form gets a length messageLink to this section
- Please keep your name under 100 characters: the name is too long.
- Please keep the message under 5,000 characters: the message is too long.
- This message is too long: the form sent more than 20,000 characters in all.
Show these words to the visitor, and limit your form's fields to the same lengths so they rarely see them.