PlatformXeDocs
Get API Key

Messaging

Send emails and SMS via the SDK.

The SDK provides methods for sending transactional email and SMS through PlatformXe's multi-provider fallback pipeline.

Send email

const result = await px.sendEmail({
  from: 'Your App <hello@yourapp.com>',
  to: ['user@example.com'],
  subject: 'Order Confirmation',
  html: '<h1>Your order is confirmed</h1><p>Order #12345</p>',
});

console.log(result.data.messageId); // "msg_abc123" (absent when queued)
console.log(result.data.queued);    // false
# Python: from_ is required (keyword-only); reply_to is a string or a list of 1 to 5.
result = client.messaging.send_email(
    "user@example.com",
    "Order Confirmation",
    "<h1>Your order is confirmed</h1>",
    reply_to=["support@yourapp.com", "Billing <billing@yourapp.com>"],
    from_="Your App <hello@yourapp.com>",
)
// Go: the input keys are the request fields; "from" is required.
res, err := client.Messaging.SendEmail(map[string]interface{}{
	"from":    "Your App <hello@yourapp.com>",
	"to":      []string{"user@example.com"},
	"subject": "Order Confirmation",
	"html":    "<h1>Your order is confirmed</h1>",
	"replyTo": []string{"support@yourapp.com"},
})
// res.MessageID, res.Provider, res.Queued

Parameters

FieldTypeRequiredDescription
fromstringYesSender: an address or Name <address>, at most 320 characters. The address actually used follows the sender rules
tostring[]YesRecipients: one address or Name <address> per entry, at most 320 characters; quote a name holding , ; : ( or )
cc / bccstring[]NoUp to 10 entries each, read like to
subjectstringYesEmail subject line
htmlstringYesPre-rendered HTML body
textstringNoPlain-text part
replyTostring or string[]NoOne reply-to address, or a list of 1 to 5 (each at most 320 characters). Python: reply_to
attachmentsArray<{ filename, content }>NoA non-empty filename and base64 content, standard or URL-safe, at most 4,400,000 base64 characters in all (another shape, or more: 400 VALIDATION_ERROR; the whole request body is limited to 4.5 MB)
callerRefstringNoYour tracking reference, at most 200 characters, stored with the email's message log entries. Python: caller_ref
templateId + variablesstring, Record<string, string>NoRender a built-in, platform or your organisation's template in place of subject / html / text, with variables or none (another organisation's or an unknown id: 404 NOT_FOUND). Python: template_id, variables

Response type

interface SendEmailResponse {
  success: true;
  data: {
    messageId?: string;   // absent when the email was queued
    provider: string;     // chain position: 'primary', 'fallback_1', ...; 'none' when queued
    queued: boolean;      // true when every provider failed and it was queued for retry
    deduplicated?: true;  // with queued: your identical email was already in the retry queue
  };
}

Errors

A request every provider refuses as sent (an invalid recipient, replyTo or attachment) fails with 400 BAD_REQUEST: the TypeScript SDK throws ValidationError, Python raises PlatformXeAPIError and Go returns an *APIError with StatusCode 400. The email is not sent, not queued and not retried; fix the request and send it again. A refusal by one provider only is not an error: the next provider sends the email. A to, cc or bcc entry that is not one address (empty, a name only, two addresses), or a from, recipient or replyTo entry over 320 characters, fails with 400 VALIDATION_ERROR, and a replyTo of another type (an object, or more than 5 addresses) with 400 BAD_REQUEST, before anything is sent. See Send Email.

An email neither sent nor queued fails with one of three errors, each with a Retry-After header. Nothing was sent; send it again after that many seconds, not sooner.

ErrorStatusWhenPythonGo
EMAIL_RATE_LIMITED429A sending limit for the recipient was reached. Retry-After is the real wait, up to 24 hoursPlatformXeAPIError, retry_after*APIError, Code ErrCodeEmailRateLimited, RetryAfter
EMAIL_NOT_ACCEPTED503Every provider failed and the retry queue could not store the email (Retry-After 60)PlatformXeAPIError, retry_after*APIError, Code ErrCodeEmailNotAccepted, RetryAfter
EMAIL_PROVIDER_UNAVAILABLE503No email route is available (Retry-After 300)PlatformXeAPIError, retry_after*APIError, Code ErrCodeEmailProviderUnavailable, RetryAfter

Neither SDK sends the email again by itself for these errors: Python never re-sends a request the API answered, and the Go client returns these three codes at once. The wait is yours to schedule. For any other 429, 502, 503 or 504, the Go client retries no sooner than Retry-After: it sleeps a wait of up to 5 seconds in place of its shorter backoff, and returns the error at once when the wait is longer.

A repeat of an email that is already waiting in the retry queue is not an error: the answer is queued: true with deduplicated: true (Go: res.Deduplicated; Python: result["deduplicated"]). See Duplicate sends while queued. A successful answer is always sent or queued.

Send SMS

const result = await px.sendSms({
  to: '+2348012345678',
  body: 'Your verification code is 123456',
});

console.log(result.data.messageId);

Parameters

FieldTypeRequiredDescription
tostringYesRecipient phone number (E.164 format)
bodystringYesMessage text
fromstringNoSender ID

Response type

interface SendSmsResponse {
  success: true;
  data: {
    messageId: string;
    status: 'queued' | 'sent' | 'failed';
  };
}

WhatsApp link and health

buildWhatsAppLink builds a click-to-chat link (wa.me and whatsapp://) and sends nothing. whatsappHealth runs PlatformXe's WhatsApp configuration probe: the operating mode, a verdict, each check with its remediation, and your organisation's own most recent failed sends (recipients masked; never another organisation's, whatever its caller service is called). TypeScript 1.14.0; Python and Go already had them (async Python 1.11.0).

const link = await client.messaging.buildWhatsAppLink({ to: '+2348012345678', message: 'Your booking is confirmed' });
const health = await client.messaging.whatsappHealth();
console.log(health.mode, health.verdict);
health = client.messaging.whatsapp_health()
health, err := client.Messaging.WhatsAppHealth()

Email health

emailHealth (Python email_health, Go EmailHealth) returns the email routes in the order they are tried, each with its circuit-breaker state, and your organisation's retry queue counts. Each route is named by its chain position (primary, fallback_1, ...), never a provider name; a PlatformXe platform key reads the names. See Email health.

Both email and SMS use multi-provider fallback with circuit breakers. If the primary provider fails, PlatformXe automatically retries with backup providers. Messages that fail all providers are added to a persistent retry queue.

Scopes required

MethodScope
px.sendEmail()messaging:send
px.sendSms()messaging:send