# Send Email (`apify/send-mail`) Actor

Send a custom email to one or more recipients. This Actor is useful for notifications and reporting. It can be invoked directly from code or via webhook integration after another Actor finishes.

- **URL**: https://apify.com/apify/send-mail.md
- **Developed by:** [Apify](https://apify.com/apify) (Apify)
- **Categories:** Automation, Integrations
- **Stats:** 3,297 total users, 195 monthly users, 89.1% runs succeeded, 106 bookmarks
- **User rating**: 4.98 out of 5 stars

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-usage

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Apify Send Mail

Apify actor to send mail.

This actor is meant to be used as a reporting tool and must not be used to send promotional or spammy emails. Using it as such will lead to the user being banned on the Apify platform.

### Input

**Example:**
```javascript
{
    // Email address of the recipient(s) (e.g. "Bob <bob@example.com>")
    // Required
    to: String,
    // Email CC same format as to
    // Required
    cc: String
    // Email BCC same format as to
    bcc: String
    // Email subject
    // Required
    subject: String,
    // Text body of Email
    // Required
    text: String,
    // Email attachments
    attachments: [Object]
}
````

**Attributes:**

- `to` - Email address of the recipient(s), you can comma-separate multiple addresses (e.g. "Bob <bob@example.com>" or "bob@example.com, hello@apify.com")
- `cc` - Email CC same format as to
- `bcc` - Email BCC same format as to
- `subject` - Email subject
- `text` - Text body of Email
- `html` - HTML body of Email
- `replyTo` - Email address which will be set when recipient will try to reply to mail. (Uses header `Reply-To` see [doc](https://tools.ietf.org/html/rfc5322#section-3.6.2))
- `attachments` - array of attachments in base64 string, example:

```javascript
[{
    // attachment file name
    filename: String,
    // attachment content in base64 string
    data: String
}]
```

### Limitations

To prevent abuse, the actor limits the number of email recipients:

- Users on the free plan can only send emails to their own email address associated with their Apify account.
- Paying users can send emails to up to 20 different recipients.

### Usage

#### From other Apify actor

```javascript
await Apify.call('apify/send-mail', {
    to: 'test@apify.com',
    subject: 'Test from act',
    text: "Email text",
    attachments: [{
        filename: 'test.txt',
        data: 'dGVzdCBzZmFzZGFzZGFzZGFzZA'
    }]
});
```

#### From Apify actor/task webhook

Calling this actor via a [webhook](https://docs.apify.com/webhooks) is very handy because you can ensure it is sent only after specific event happens. Here is an example setup to send email after failed run.

1. Open **Webhooks** tab of the actor/task that you want to monitor.
2. Set **Event types** to `Run failed` and `Run timed out`.
3. **URL** is the RUN API endpoint of this actor, just fill your API token - https://api.apify.com/v2/acts/apify~send-mail/runs?token=APIFY\_API\_TOKEN
4. **Payload template** represents the body that is sent to this actor:

Example of payload that sends run ID in the email text:

```
{
    "to": "test@apify.com",
    "subject": "Task Scrape-website run failed",
    "text": {{eventData.actorRunId}}
}
```

# Actor input Schema

## `to` (type: `string`):

Email address of the recipient(s), you can comma-separate multiple addresses.

## `cc` (type: `string`):

Email CC same format as to.

## `bcc` (type: `string`):

Email BCC same format as to.

## `subject` (type: `string`):

(required) Text body of Email

## `text` (type: `string`):

(required HTML or text) Text body of Email

## `html` (type: `string`):

(required HTML or text) HTML body of Email

## `replyTo` (type: `string`):

Email address which will be set when recipient will try to reply to mail. Uses header Reply-To <a href= "https://tools.ietf.org/html/rfc5322#section-3.6.2">see doc </a>

## `isMock` (type: `boolean`):

For test purposes - log process to console but not send the e-mail

## Actor input object example

```json
{
  "to": "alice@example.com, bob@example.com",
  "cc": "copy@apify.com",
  "bcc": "unseencopy@apify.com",
  "subject": "Send Email notification",
  "text": "Hi there!",
  "html": "<H1> Hi there! </H1>",
  "replyTo": "replyto@apify.com",
  "isMock": false
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "to": "alice@example.com, bob@example.com",
    "subject": "Send Email notification"
};

// Run the Actor and wait for it to finish
const run = await client.actor("apify/send-mail").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "to": "alice@example.com, bob@example.com",
    "subject": "Send Email notification",
}

# Run the Actor and wait for it to finish
run = client.actor("apify/send-mail").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "to": "alice@example.com, bob@example.com",
  "subject": "Send Email notification"
}' |
apify call apify/send-mail --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=apify/send-mail",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Send Email",
        "description": "Send a custom email to one or more recipients. This Actor is useful for notifications and reporting. It can be invoked directly from code or via webhook integration after another Actor finishes.",
        "version": "0.3",
        "x-build-id": "tTUCBjcqRszneYCoX"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/apify~send-mail/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-apify-send-mail",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/apify~send-mail/runs": {
            "post": {
                "operationId": "runs-sync-apify-send-mail",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/apify~send-mail/run-sync": {
            "post": {
                "operationId": "run-sync-apify-send-mail",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "to",
                    "subject"
                ],
                "properties": {
                    "to": {
                        "title": "To",
                        "type": "string",
                        "description": "Email address of the recipient(s), you can comma-separate multiple addresses."
                    },
                    "cc": {
                        "title": "Cc",
                        "type": "string",
                        "description": "Email CC same format as to."
                    },
                    "bcc": {
                        "title": "Bcc",
                        "type": "string",
                        "description": "Email BCC same format as to."
                    },
                    "subject": {
                        "title": "Subject",
                        "type": "string",
                        "description": "(required) Text body of Email"
                    },
                    "text": {
                        "title": "Text",
                        "type": "string",
                        "description": "(required HTML or text) Text body of Email"
                    },
                    "html": {
                        "title": "HTML",
                        "type": "string",
                        "description": "(required HTML or text) HTML body of Email"
                    },
                    "replyTo": {
                        "title": "Reply to",
                        "type": "string",
                        "description": "Email address which will be set when recipient will try to reply to mail. Uses header Reply-To <a href= \"https://tools.ietf.org/html/rfc5322#section-3.6.2\">see doc </a>"
                    },
                    "isMock": {
                        "title": "Mock email",
                        "type": "boolean",
                        "description": "For test purposes - log process to console but not send the e-mail",
                        "default": false
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
