# Send email

> Sends an email. It is queued immediately and delivered within seconds, or at `scheduled_at`.

Source: https://mailvina.com/docs/api-reference/emails/send-email · Base URL: https://api.mailvina.com · Guide: https://mailvina.com/docs/send-email

`POST /emails`

**Headers**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | no | Optional. Repeating a request with the same key within 24 hours returns the original email instead of sending again. |

**Body parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `from` | `string` | yes | Sender, e.g. `"Acme <hello@mail.acme.com>"`. The domain must be verified (or use the sandbox sender). Optional when `template` has a default sender. |
| `to` | `string \| string[]` | yes | Recipient addresses. Up to 50 recipients across `to`, `cc` and `bcc`. |
| `subject` | `string` | yes | Subject line. Optional when `template` provides one. |
| `html` | `string` | no | HTML body. Either `html`, `text` or `template` is required. |
| `text` | `string` | no | Plain-text body. Generated from `html` when omitted. |
| `cc` | `string \| string[]` | no | Carbon-copy recipients. |
| `bcc` | `string \| string[]` | no | Blind carbon-copy recipients. |
| `reply_to` | `string \| string[]` | no | Reply-To address(es). Defaults to the template’s, if it has one. |
| `headers` | `object` | no | Custom MIME headers as name → value pairs, e.g. `{ "X-Entity-Ref-ID": "123" }`. |
| `attachments` | `object[]` | no | Files to attach. Up to 40 MB per email in total, attachments included. |
| `attachments[].filename` | `string` | yes | File name shown to the recipient, e.g. `invoice.pdf`. |
| `attachments[].content` | `string` | yes | The file, base64-encoded. |
| `attachments[].content_type` | `string` | no | MIME type, e.g. `application/pdf`. Guessed from the file name when omitted. |
| `tags` | `object[]` | no | Labels echoed in webhooks so you can match events to your own records. |
| `tags[].name` | `string` | yes | Tag name, e.g. `category`. |
| `tags[].value` | `string` | yes | Tag value, e.g. `welcome`. |
| `scheduled_at` | `string` | no | ISO 8601 timestamp up to 30 days ahead. The email is created with status `scheduled`. |
| `template` | `object` | no | Send a stored template. Its subject, HTML, text, sender and Reply-To are used for any of those you leave out. |
| `template.id` | `string` | yes | The template’s **ID or alias**, e.g. `"welcome-email"`. |
| `template.variables` | `object` | no | Values for the template’s variables, e.g. `{ "name": "Ada" }` fills `{{name}}`. Missing values use the fallback in `{{name\|fallback}}`, or become empty. |

To send a stored template, pass its ID or alias with the variables to fill in: `{ "from": "Acme <hello@mail.acme.com>", "to": "ada@example.com", "template": { "id": "welcome-email", "variables": { "name": "Ada" } } }`. Anything you also pass (such as `subject`) overrides the template’s.

**Request**

```bash
curl -X POST 'https://api.mailvina.com/emails' \
  -H 'Authorization: Bearer mv_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "from": "Acme <hello@mail.acme.com>",
  "to": [
    "ada@example.com"
  ],
  "subject": "Welcome to Acme",
  "html": "<p>Hi Ada!</p>",
  "tags": [
    {
      "name": "category",
      "value": "welcome"
    }
  ]
}'
```

```js
const res = await fetch('https://api.mailvina.com/emails', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MAILVINA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "from": "Acme <hello@mail.acme.com>",
    "to": [
      "ada@example.com"
    ],
    "subject": "Welcome to Acme",
    "html": "<p>Hi Ada!</p>",
    "tags": [
      {
        "name": "category",
        "value": "welcome"
      }
    ]
  }),
});
const data = await res.json();
```

```python
import os, requests

res = requests.post(
    "https://api.mailvina.com/emails",
    headers={"Authorization": f"Bearer {os.environ['MAILVINA_API_KEY']}"},
    json={
        "from": "Acme <hello@mail.acme.com>",
        "to": [
            "ada@example.com"
        ],
        "subject": "Welcome to Acme",
        "html": "<p>Hi Ada!</p>",
        "tags": [
            {
                "name": "category",
                "value": "welcome"
            }
        ]
    },
)
print(res.json())
```

**Response**

```json
{
  "id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
}
```
