# 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
- **Features:** Limited permissions
- **Stats:** 3,865 total users, 418 monthly users, 88.9% runs succeeded, 108 bookmarks
- **User rating**: 4.99 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/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

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

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# 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(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).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": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,apify/send-mail"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/e643gqfZae2TfQEbA/builds/IltU4G1ItrdtF1muG/openapi.json
