> ## Documentation Index
> Fetch the complete documentation index at: https://docs.botmailroom.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Send an Email

> Send an email from your inbox

<Warning>
  Before you can send an email, you need to [create an
  inbox](/documentation/quickstart).
</Warning>

## Limits

* 10MB total attachment size
* 10 emails per day for the free tier, 1000 emails per day for the paid tiers

If you need higher limits, [contact us](mailto:support@inbox.botmailroom.com) to upgrade.

## REST API

#### 1. Create an Api Key (if you don't already have one)

<Snippet file="create_api_key.mdx" />

#### 2. Send an Email

<Warning>
  Make sure to pass the `api_key` you created in the previous step in the
  `Authorization` header. Also make sure to replace `FROM_ADDRESS` with the
  address of the BotMailRoom inbox you want to send the email from. And change
  the `to_addresses` to the email address you want to send the email to.
</Warning>

```bash
curl -X POST "https://api.botmailroom.com/api/v1/email/send" \
     -H "Authorization: Bearer ${api_key}" \
     -H "Content-Type: application/json" \
     -d '{
       "from_address": FROM_ADDRESS,
       "subject": "Hello from Bot Mailroom",
       "plain_text": "Hello from Bot Mailroom. We are testing our email sending functionality.",
       "to_addresses": [
         {
           "address": "CHANGE_THIS@CHANGE_THIS.com",
           "name": null
         },
       ]
     }'
```

<Info>
  See the [API Reference](/documentation/api-reference/email/send-email) for
  more information on the request body.
</Info>

#### Optional - Add an Attachment

Add an attachment to the attachment pool by sending a request to the [add
attachment to pool endpoint](/documentation/api-reference/email/add-attachment-to-pool).

<Warning>
  Make sure to pass the `api_key` you created in the previous step in the
  `Authorization` header. Also make sure to replace `path/to/file` with the path
  to the file you want to add to the attachment pool.
</Warning>

```bash
curl -X POST "https://api.botmailroom.com/api/v1/email/add-attachment-to-pool" \
     -H "Authorization: Bearer ${api_key}" \
     -H "Content-Type: multipart/form-data" \
     -F "file=@path/to/file"
```

The response will contain the ID of the attachment, which you can then use in
the `send_email` request.

```bash
curl -X POST "https://api.botmailroom.com/api/v1/email/send" \
     -H "Authorization: Bearer ${api_key}" \
     -H "Content-Type: application/json" \
     -d '{
       "from_address": FROM_ADDRESS,
       "subject": "Hello from Bot Mailroom",
       "plain_text": "Hello from Bot Mailroom. We are testing our email sending functionality.",
       "to_addresses": [
         {
           "address": "CHANGE_THIS@CHANGE_THIS.com",
           "name": null
         },
       ],
       "attachment_ids": [
         ATTACHMENT_ID
       ]
     }'
```

## Python Client

#### 1. Create an Api Key (if you don't already have one)

<Snippet file="create_api_key.mdx" />

#### 2. Install the Client (if you haven't already)

```bash
pip install botmailroom
```

#### 3. Initialize the Client

```python
from botmailroom import BotMailRoom

client = BotMailRoom(api_key="your_api_key") # or set the BOTMAILROOM_API_KEY environment variable
```

#### 4. Send an Email

<Warning>
  Make sure to replace `FROM_ADDRESS` with the address of the BotMailRoom inbox
  you want to send the email from. And change the `to_addresses` to the email
  address you want to send the email to.
</Warning>

```python
email_id = client.send_email(
    from_address=FROM_ADDRESS,
    subject="Hello from Bot Mailroom",
    to_addresses=[{"address": "CHANGE_THIS@CHANGE_THIS.com", "name": None}],
    content="Hello from Bot Mailroom. We are testing our email sending functionality.",
)
```

<Info>
  See the [API Reference](/documentation/api-reference/email/send-email) for
  more information on the request body.
</Info>

#### Optional - Add an Attachment

With the python client, you can just pass the file info directly to the
`send_email` method and it will handle adding the attachment to the pool for
you.

```python
filename = "path/to/file"

with open(filename, "rb") as file:
    file_bytes = file.read()

attachment_raw = (file_bytes, filename.split("/")[-1], "application/pdf")

email_id = client.send_email(
    from_address=FROM_ADDRESS,
    subject="Hello from Bot Mailroom",
    to_addresses=[{"address": "CHANGE_THIS@CHANGE_THIS.com", "name": None}],
    content="Hello from Bot Mailroom. We are testing our email sending functionality.",
    attachments_raw=[attachment_raw],
)
```

## TypeScript Client

#### 1. Create an Api Key (if you don't already have one)

<Snippet file="create_api_key.mdx" />

#### 2. Install the Client

```bash
npm install botmailroom
# or
yarn add botmailroom
```

#### 3. Initialize the Client

```typescript
import { BotMailRoom } from "botmailroom";

const client = new BotMailRoom("your_api_key"); // or set the BOTMAILROOM_API_KEY environment variable
```

#### 4. Send an Email

<Warning>
  Make sure to replace `FROM_ADDRESS` with the address of the BotMailRoom inbox
  you want to send the email from. And change the `to_addresses` to the email
  address you want to send the email to.
</Warning>

```typescript
const emailId = await client.sendEmail({
  fromAddress: FROM_ADDRESS,
  content:
    "Hello from Bot Mailroom. We are testing our email sending functionality.",
  subject: "Hello from Bot Mailroom",
  toAddresses: [{ address: "CHANGE_THIS@CHANGE_THIS.com", name: null }],
});
```

<Info>
  See the [API Reference](/documentation/api-reference/email/send-email) for
  more information on the available parameters.
</Info>

#### Optional - Add an Attachment

With the TypeScript client, you can pass raw attachments directly to the `sendEmail` method:

```typescript
const fileBuffer = new ArrayBuffer(8); // Your file data here
const attachment = {
  filename: "document.pdf",
  file: fileBuffer,
  contentType: "application/pdf",
};

const emailId = await client.sendEmail({
  fromAddress: FROM_ADDRESS,
  content:
    "Hello from Bot Mailroom. We are testing our email sending functionality.",
  subject: "Hello from Bot Mailroom",
  toAddresses: [{ address: "CHANGE_THIS@CHANGE_THIS.com", name: null }],
  attachmentsRaw: [attachment],
});
```
