# Schedule email

> Send an email at a future time with scheduled_at, then reschedule or cancel it before it goes out.

Pass a `scheduled_at` timestamp to `POST /emails` to hold the email and deliver it later. The value is an **ISO 8601** datetime — always send it with an explicit timezone offset (or a trailing `Z` for UTC) so there is no ambiguity about when it fires.

## Schedule a send

When `scheduled_at` is in the future, SendPing stores the email with status `scheduled` and enqueues an internal job that the scheduler dispatches at the requested time. Open/click tracking, custom headers, and attachments are applied at the *actual* send time, so a scheduled email is assembled identically to an immediate one.

> **Note:** Emails can be scheduled up to **30 days** in advance. A `scheduled_at` further out than that is rejected with a `validation_error`.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": ["you@yourdomain.com"],
  "subject": "Your weekly digest",
  "html": "<p>Here is what you missed.</p>",
  "scheduled_at": "2026-06-24T09:00:00Z"
});
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": [
    "you@yourdomain.com"
  ],
  "subject": "Your weekly digest",
  "html": "<p>Here is what you missed.</p>",
  "scheduled_at": "2026-06-24T09:00:00Z"
})
```

**PHP**

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

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->emails->send([
  'from' => "Acme <hello@yourdomain.com>",
  'to' => [
    "you@yourdomain.com"
  ],
  'subject' => "Your weekly digest",
  'html' => "<p>Here is what you missed.</p>",
  'scheduled_at' => "2026-06-24T09:00:00Z"
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": [
    "you@yourdomain.com"
  ],
  "subject": "Your weekly digest",
  "html": "<p>Here is what you missed.</p>",
  "scheduled_at": "2026-06-24T09:00:00Z"
})
```

**Go**

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

client := sendping.NewClient("mb_xxxxxxxxx")

sent, err := client.Emails.Send(&sendping.SendEmailRequest{
    From:        "Acme <hello@yourdomain.com>",
    To:          []string{"you@yourdomain.com"},
    Subject:     "Your weekly digest",
    Html:        "<p>Here is what you missed.</p>",
    ScheduledAt: "2026-06-24T09:00:00Z",
})
```

**Rust**

```rust
use sendping::{SendEmailOptions, SendPing};

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

let params = SendEmailOptions::new(
    "Acme <hello@yourdomain.com>",
    ["you@yourdomain.com"],
    "Your weekly digest",
)
.with_html("<p>Here is what you missed.</p>")
.with_scheduled_at("2026-06-24T09:00:00Z");
let _sent = mb.emails.send(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.SendEmailRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

SendEmailRequest request = SendEmailRequest.builder()
        .from("Acme <hello@yourdomain.com>")
        .to("you@yourdomain.com")
        .subject("Your weekly digest")
        .html("<p>Here is what you missed.</p>")
        .scheduledAt("2026-06-24T09:00:00Z")
        .build();

SendPingResponse response = sendping.emails().send(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.EmailSendAsync(new EmailMessage
{
    From = "Acme <hello@yourdomain.com>",
    To = "you@yourdomain.com",
    Subject = "Your weekly digest",
    HtmlBody = "<p>Here is what you missed.</p>",
    ScheduledAt = "2026-06-24T09:00:00Z",
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/emails' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "from": "Acme <hello@yourdomain.com>",
  "to": ["you@yourdomain.com"],
  "subject": "Your weekly digest",
  "html": "<p>Here is what you missed.</p>",
  "scheduled_at": "2026-06-24T09:00:00Z"
}'
```

**CLI**

```bash
sendping emails send \
  --from 'Acme <hello@yourdomain.com>' \
  --to 'you@yourdomain.com' \
  --subject 'Your weekly digest' \
  --html '<p>Here is what you missed.</p>' \
  --scheduled-at '2026-06-24T09:00:00Z'
```

> **Note:** If `scheduled_at` is in the past (or omitted), the email is sent immediately and starts as `sent` rather than `scheduled`.

## Reschedule

Change the delivery time of a still-`scheduled` email with [PATCH /emails/:id](https://www.sendping.co/docs/api/emails-update), passing a new `scheduled_at`. Only emails in the `scheduled` state can be rescheduled — once an email has been sent, the time is fixed.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.emails.update('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794', { "scheduled_at": "2026-06-25T09:00:00Z" });
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Emails.update("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", {
  "scheduled_at": "2026-06-25T09:00:00Z"
})
```

**PHP**

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

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->emails->update('49a3999c-0ce1-4ea6-ab68-afcd6dc2e794', [
  'scheduled_at' => "2026-06-25T09:00:00Z"
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Emails.update("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", {
  "scheduled_at": "2026-06-25T09:00:00Z"
})
```

**Go**

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

client := sendping.NewClient("mb_xxxxxxxxx")

updated, err := client.Emails.Update("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", &sendping.UpdateEmailRequest{
    ScheduledAt: "2026-06-25T09:00:00Z",
})
```

**Rust**

```rust
use sendping::SendPing;

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

let _updated = mb.emails.update("49a3999c-0ce1-4ea6-ab68-afcd6dc2e794", "2026-06-25T09:00:00Z").await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

SendPingResponse response = sendping.emails().update(
        "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794",
        "2026-06-25T09:00:00Z");
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.EmailUpdateAsync(
    "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794",
    "2026-06-25T09:00:00Z");
```

**cURL**

```bash
curl -X PATCH 'https://www.sendping.co/api/emails/49a3999c-0ce1-4ea6-ab68-afcd6dc2e794' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{ "scheduled_at": "2026-06-25T09:00:00Z" }'
```

**CLI**

```bash
sendping emails update 49a3999c-0ce1-4ea6-ab68-afcd6dc2e794 \
  --scheduled-at '2026-06-25T09:00:00Z'
```

## Cancel

Cancel a still-`scheduled` email with [POST /emails/:id/cancel](https://www.sendping.co/docs/api/emails-cancel). The email moves to `canceled` and the pending job is removed, so it will never be sent. Only `scheduled` emails can be canceled.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

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

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

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

**PHP**

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

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

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

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

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

**Go**

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

client := sendping.NewClient("mb_xxxxxxxxx")

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

**Rust**

```rust
use sendping::SendPing;

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

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

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

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

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

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

**cURL**

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

**CLI**

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

> **Warning:** Once an email is canceled it cannot be rescheduled — submit a fresh `POST /emails` to send it later.

> **Warning:** Attempting to reschedule or cancel an email that is no longer `scheduled` returns a `validation_error` — by then it has already been queued for delivery.

## Scheduled email failures

A scheduled email may still fail when its run time arrives — the dispatch is attempted later than the original request, so conditions can change in between. When this happens the email moves to `failed` and the reason is recorded on its [event log](https://www.sendping.co/docs/emails/managing). Common causes:

- **The recipient was suppressed in the meantime** — if every `to` recipient hard-bounced, complained, or unsubscribed between scheduling and dispatch, there is no one left to deliver to.
- **The sending domain is no longer verified** — if the `from` domain’s verification lapsed before the run time, the send is rejected.
- **Your sending quota stayed exhausted** — the send is retried hourly for about three days; if there is still no headroom it is failed rather than queued forever.
