# Cancel an email

> POST /emails/:id/cancel — cancel a scheduled email.

`POST /emails/:id/cancel`

Cancel a still-`scheduled` email so it is never sent. The email moves to the `canceled` status and its pending delivery job is removed. Only emails in the `scheduled` state can be canceled. See [Schedule email](https://www.senddart.com/docs/emails/schedule).

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | Yes | The id of the scheduled email to cancel. |

## Request

**Node.js**

```js
import { SendDart } from 'senddart';

const mb = new SendDart('mb_xxxxxxxxx');

const { data, error } = await mb.emails.cancel('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794');
console.log({ data, error });
```

**Ruby**

```ruby
require "senddart"

SendDart.api_key = "mb_xxxxxxxxx"

SendDart::Emails.cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendDart\SendDart;

$senddart = SendDart::client('mb_xxxxxxxxx');

$senddart->emails->cancel('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794');
```

**Python**

```python
import senddart

senddart.api_key = "mb_xxxxxxxxx"

senddart.Emails.cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
```

**Go**

```go
import "github.com/shekhu10/senddart-sdks/senddart-go"

client := senddart.NewClient("mb_xxxxxxxxx")

canceled, err := client.Emails.Cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794")
```

**Rust**

```rust
use senddart::SendDart;

let mb = SendDart::new("mb_xxxxxxxxx");

let _canceled = mb.emails.cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794").await?;
```

**Java**

```java
import com.senddart.SendDart;
import com.senddart.SendDartResponse;

SendDart senddart = new SendDart("mb_xxxxxxxxx");

SendDartResponse response = senddart.emails().cancel("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794");
```

**.NET**

```csharp
using SendDart;

ISendDart senddart = SendDartClient.Create("mb_xxxxxxxxx");

var resp = await senddart.EmailCancelAsync("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794");
```

**cURL**

```bash
curl -X POST 'https://www.senddart.com/api/emails/49a3999c-0ce1-4ea6-ab68-afcd6dc2e794/cancel' \
  -H 'Authorization: Bearer mb_xxxxxxxxx'
```

**CLI**

```bash
senddart emails cancel 49a3999c-0ce1-4ea6-ab68-afcd6dc2e794
```

## Response

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

## Errors

Returns `not_found` (404) if the email does not exist for your account; `validation_error` if the email is not in the `scheduled` state (i.e. it has already been sent or canceled). See the [error reference](https://www.senddart.com/docs/api/errors).
