Get started
Quickstart
Four requests take you from a new token to a sent email. Use the language tabs to see each step in the language you work in; your choice is remembered on every page.
Keep the token where your server can read it#
The hotel gives you a token that looks like
ems_followed by 12 characters, an underscore and 40 more. It is shown once. Store it as a secret on the server that will send email, never in a browser, a mobile app or a repository.Shell # macOS and Linux (add it to your secret manager for production) export EMAIL_API_TOKEN="ems_..."PowerShell # Windows PowerShell, for this session $env:EMAIL_API_TOKEN = "ems_..."Check what the token can do#
GET /v1/meanswers with the token's permissions, the sender addresses it may use, its limits and today's usage. It needs no particular permission, so it is the safest first call.Shell curl -sS https://email.madagascarhotelags.com/v1/me \ -H "Authorization: Bearer $EMAIL_API_TOKEN"PowerShell $headers = @{ Authorization = "Bearer $env:EMAIL_API_TOKEN" } Invoke-RestMethod -Uri https://email.madagascarhotelags.com/v1/me -Headers $headersJavaScript const res = await fetch('https://email.madagascarhotelags.com/v1/me', { headers: { Authorization: `Bearer ${process.env.EMAIL_API_TOKEN}` }, }); console.log(res.status, await res.json());Python import os, requests res = requests.get( "https://email.madagascarhotelags.com/v1/me", headers={"Authorization": f"Bearer {os.environ['EMAIL_API_TOKEN']}"}, timeout=10, ) print(res.status_code, res.json())PHP <?php $ch = curl_init('https://email.madagascarhotelags.com/v1/me'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('EMAIL_API_TOKEN')], ]); var_dump(json_decode(curl_exec($ch), true));A
200with your token's name means you are ready. A401means the token is missing, mistyped or no longer valid: the request builder can check its shape without sending it anywhere.Send a message#
Post the message as JSON. The
Idempotency-Keymakes the request safe to repeat: if your code retries after a timeout, the API returns the first answer instead of sending a second email.Shell curl -sS https://email.madagascarhotelags.com/v1/messages \ -H "Authorization: Bearer $EMAIL_API_TOKEN" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: booking-4821-confirmation" \ -d '{ "to": ["guest@example.com"], "subject": "Your stay is confirmed", "text": "Luna checks in on Friday at 10:00. Reply to this email if anything changes.", "html": "<p>Luna checks in on <strong>Friday at 10:00</strong>.</p><p>Reply to this email if anything changes.</p>" }'PowerShell $headers = @{ Authorization = "Bearer $env:EMAIL_API_TOKEN" "Idempotency-Key" = "booking-4821-confirmation" } $body = @{ to = @("guest@example.com") subject = "Your stay is confirmed" text = "Luna checks in on Friday at 10:00." } | ConvertTo-Json Invoke-RestMethod -Method Post -Uri https://email.madagascarhotelags.com/v1/messages ` -Headers $headers -ContentType "application/json" -Body $bodyJavaScript const res = await fetch('https://email.madagascarhotelags.com/v1/messages', { method: 'POST', headers: { Authorization: `Bearer ${process.env.EMAIL_API_TOKEN}`, 'Content-Type': 'application/json', 'Idempotency-Key': 'booking-4821-confirmation', }, body: JSON.stringify({ to: ['guest@example.com'], subject: 'Your stay is confirmed', text: 'Luna checks in on Friday at 10:00.', }), }); const result = await res.json(); if (!res.ok) throw new Error(`${result.code}: ${result.detail}`); console.log(result.id); // msg_...Python import os, requests res = requests.post( "https://email.madagascarhotelags.com/v1/messages", headers={ "Authorization": f"Bearer {os.environ['EMAIL_API_TOKEN']}", "Idempotency-Key": "booking-4821-confirmation", }, json={ "to": ["guest@example.com"], "subject": "Your stay is confirmed", "text": "Luna checks in on Friday at 10:00.", }, timeout=10, ) result = res.json() if not res.ok: raise RuntimeError(f"{result['code']}: {result['detail']}") print(result["id"]) # msg_...PHP <?php $ch = curl_init('https://email.madagascarhotelags.com/v1/messages'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('EMAIL_API_TOKEN'), 'Content-Type: application/json', 'Idempotency-Key: booking-4821-confirmation', ], CURLOPT_POSTFIELDS => json_encode([ 'to' => ['guest@example.com'], 'subject' => 'Your stay is confirmed', 'text' => 'Luna checks in on Friday at 10:00.', ]), ]); $result = json_decode(curl_exec($ch), true); if (curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 202) { throw new RuntimeException($result['code'] . ': ' . $result['detail']); } echo $result['id']; // msg_...The answer is
202 Acceptedwith the message id. "Accepted" means the API has the message and has queued it; delivery happens a moment later.Response 202 { "id": "msg_01k6qzexample0000000000000", "status": "queued", "created_at": "2026-10-01T15:04:05.000Z" }Follow it#
Ask for the message by id (this needs the token's
readpermission). Within a few seconds the status moves from queued to sent.Shell curl -sS https://email.madagascarhotelags.com/v1/messages/msg_01k6qzexample0000000000000 \ -H "Authorization: Bearer $EMAIL_API_TOKEN"PowerShell $headers = @{ Authorization = "Bearer $env:EMAIL_API_TOKEN" } Invoke-RestMethod -Uri https://email.madagascarhotelags.com/v1/messages/msg_01k6qzexample0000000000000 -Headers $headersJavaScript const res = await fetch(`https://email.madagascarhotelags.com/v1/messages/${id}`, { headers: { Authorization: `Bearer ${process.env.EMAIL_API_TOKEN}` }, }); const message = await res.json(); console.log(message.status, message.error);Python res = requests.get( f"https://email.madagascarhotelags.com/v1/messages/{message_id}", headers={"Authorization": f"Bearer {os.environ['EMAIL_API_TOKEN']}"}, timeout=10, ) message = res.json() print(message["status"], message["error"])PHP <?php $ch = curl_init('https://email.madagascarhotelags.com/v1/messages/' . $messageId); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('EMAIL_API_TOKEN')], ]); $message = json_decode(curl_exec($ch), true); echo $message['status'];Poll no more often than every 10 seconds, and stop when the status is
sent,failedordead. Message status explains each one.
Where to go next#
- Building a real integration? Add it to your code has ready client modules with retries and timeouts.
- Need a field the example did not use (cc, bcc, reply-to, tags, scheduling)? See Sending email.
- Something answered with an error? Every code is explained in Errors.
Last reviewed 2026-10-01.