# Send an email from your site

URL: https://docs.xodia.ai/server-tasks/send-email
Last updated: 2026-11-25

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.

## What it does

- It answers `/api/contact` on 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.

> **Tip:** Only need form messages in your inbox? [Xodia Forms](https://docs.xodia.ai/content/forms) does that with no email service or key.

## Add the task

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 add

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 setting

1. 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://`.
2. 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 secret

1. 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.
2. 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, like `api.example.com`.

### Sender (EMAIL_FROM), a setting

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 setting

The inbox every message goes to. Any address you read.

## Connect your form

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:

Ask your AI:

```
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 preview

1. Turn on server tasks

   In the setup card, choose Turn on server tasks if they are off.
2. 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.
3. 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 live

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 written

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 problems

### The form answers not_set_up

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 sent

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 came

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 message

- 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.
