Salta ai contenuti

Pianificazione

Aggiungi scheduled_at a qualsiasi richiesta di invio per consegnare più tardi. L’email viene accettata subito, riceve lo stato scheduled e viene emesso un webhook email.scheduled.

Formato Esempio
ISO 8601 2026-11-01T09:00:00Z, 2026-11-01T09:00:00+01:00
Linguaggio naturale in 30 seconds, in 10 minutes, in 2 hours, in 1 day, in 1 week

Il linguaggio naturale ha la forma in <numero> <unità>, dove l’unità è una tra second, sec, minute, min, hour, hr, day, week (la s del plurale è facoltativa). Il testo non distingue maiuscole e minuscole.

Altre regole:

  • Massimo 30 giorni nel futuro. Oltre, l’API restituisce 422 validation_error.
  • Un orario nel passato, o a meno di circa un secondo da adesso, viene trattato come invia subito.
  • Le stringhe ISO senza offset di fuso orario vengono interpretate dal parser di date del server; includi sempre Z o un offset.
  • Sono accettati sia scheduled_at sia scheduledAt.
schedule.ts
import { SpacePost } from "@spacepost/node";
const spacepost = new SpacePost(process.env.SPACEPOST_API_KEY);
const { data, error } = await spacepost.emails.send({
from: "Acme <hello@acme.com>",
to: "user@example.com",
subject: "Your trial ends tomorrow",
html: "<p>Reminder.</p>",
scheduledAt: "in 1 day", // or an ISO date: "2026-11-01T09:00:00Z"
});
if (error) console.error(error);
else console.log("Scheduled", data.id);

Si possono modificare solo le email con stato scheduled. PATCH /emails/{id} sostituisce l’orario; viene messo in coda un nuovo job e quello vecchio diventa un’operazione nulla.

reschedule.ts
import { SpacePost } from "@spacepost/node";
const spacepost = new SpacePost(process.env.SPACEPOST_API_KEY);
const { error } = await spacepost.emails.update({
id: "0192e1c4-7a3b-7c1e-9d2f-3b5a8e6f4c10",
scheduledAt: "in 2 hours",
});
if (error) console.error(error);
Response (200)
{ "object": "email", "id": "0192e1c4-7a3b-7c1e-9d2f-3b5a8e6f4c10" }
cancel.ts
import { SpacePost } from "@spacepost/node";
const spacepost = new SpacePost(process.env.SPACEPOST_API_KEY);
const { error } = await spacepost.emails.cancel("0192e1c4-7a3b-7c1e-9d2f-3b5a8e6f4c10");
if (error) console.error(error); // 422 validation_error if it is no longer scheduled

Lo stato diventa canceled e l’email non viene mai inviata. Annullare o riprogrammare un’email che non è più scheduled restituisce 422 validation_error (“Only scheduled emails can be canceled”).

Imposta l’header X-SpacePost-Scheduled-At su una data ISO o su un valore in linguaggio naturale. Vedi Relay SMTP.