> For the complete documentation index, see [llms.txt](https://docs.mailofly.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mailofly.com/get-started/sending-examples.md).

# Sending examples

Minimal examples to send email with Mailofly.

You'll need:

* `MAILOFLY_API_KEY` — from [API keys](/get-started/api-keys.md)
* `acc_…` — optional; from [Accounts](/get-started/sending-accounts.md) (auto-selected when omitted)

***

## Send email (transactional)

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST https://api.mailofly.com/v1/emails \
  -H "Authorization: Bearer $MAILOFLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "Acme <onboarding@example.com>",
    "to": ["you@example.com"],
    "subject": "Hello from Mailofly",
    "html": "<p>This is a test email.</p>"
  }'
```

{% endtab %}

{% tab title="Node.js" %}

```ts
import { Mailofly } from "mailofly";

const client = new Mailofly({ apiKey: process.env.MAILOFLY_API_KEY! });

const { id } = await client.emails.send({
  from: "Acme <onboarding@example.com>",
  to: ["you@example.com"],
  subject: "Hello from Mailofly",
  html: "<p>This is a test email.</p>",
});
```

{% endtab %}

{% tab title="Python" %}

```python
import os
from mailofly import Mailofly

client = Mailofly(os.environ["MAILOFLY_API_KEY"])

result = client.emails.send({
    "from": "Acme <onboarding@example.com>",
    "to": ["you@example.com"],
    "subject": "Hello from Mailofly",
    "html": "<p>This is a test email.</p>",
})
```

{% endtab %}

{% tab title="PHP" %}

```php
$client = new \Mailofly\Client(getenv('MAILOFLY_API_KEY'));

$result = $client->emails->send([
    'from' => 'Acme <onboarding@example.com>',
    'to' => ['you@example.com'],
    'subject' => 'Hello from Mailofly',
    'html' => '<p>This is a test email.</p>',
]);
```

{% endtab %}
{% endtabs %}

***

## Batch send (up to 100 emails)

Post a JSON **array** to `POST /v1/emails/batch`. Each item uses the same shape as single send. Attachments are not supported in batch.

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST https://api.mailofly.com/v1/emails/batch \
  -H "Authorization: Bearer $MAILOFLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[
    {
      "from": "Acme <onboarding@example.com>",
      "to": ["foo@example.com"],
      "subject": "hello world",
      "html": "<h1>it works!</h1>"
    },
    {
      "from": "Acme <onboarding@example.com>",
      "to": ["bar@example.com"],
      "subject": "world hello",
      "html": "<p>it works!</p>"
    }
  ]'
```

{% endtab %}

{% tab title="Node.js" %}

```ts
const { data } = await client.batch.send([
  {
    from: "Acme <onboarding@example.com>",
    to: ["foo@example.com"],
    subject: "hello world",
    html: "<h1>it works!</h1>",
  },
  {
    from: "Acme <onboarding@example.com>",
    to: ["bar@example.com"],
    subject: "world hello",
    html: "<p>it works!</p>",
  },
]);
```

{% endtab %}
{% endtabs %}

Response: `{ "data": [{ "id": "…" }, …] }` — same order as the request array.

***

## With a template

```json
POST /v1/emails
{
  "from": "Acme <onboarding@example.com>",
  "to": ["you@example.com"],
  "template": {
    "id": "template-uuid",
    "variables": { "first_name": "Alex" }
  }
}
```

***

## Next

* [Emails API](https://docs.mailofly.com/api/emails)
* [SDKs](/resources/sdks.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mailofly.com/get-started/sending-examples.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
