Any language
The same two calls with curl, Python and Node: read Mayfly's clock, then wait for the mail.
The two calls
- Before your app sends the mail, read Mayfly's clock: the
Dateheader of any of its answers. That's yoursince, in RFC 3339. - Make your app send the mail.
- Call GET /api/v1/wait with
to,sinceandtimeout. It answers with the mail, or a 404wait_timeout.
Every call sends Authorization: Bearer and your key, here from MAYFLY_API_KEY.
curl
Needs curl 7.84 or newer, for %header{date}, and GNU date.
MAYFLY=https://mayfly.aravaltech.com
ADDRESS="signup-$(date +%s)@<your-name>.qa.aravaltech.info"
# 1. Mayfly's clock, before your app sends anything.
date_header=$(curl -sS -o /dev/null -w '%header{date}' \
-H "Authorization: Bearer $MAYFLY_API_KEY" "$MAYFLY/api/v1/mailboxes?limit=1")
since=$(date -u -d "$date_header" +%Y-%m-%dT%H:%M:%SZ) # GNU date; on macOS, gdate
# 2. Make your app send its mail to $ADDRESS here.
# 3. Wait for it.
curl -sS -G "$MAYFLY/api/v1/wait" -H "Authorization: Bearer $MAYFLY_API_KEY" \
--data-urlencode "to=$ADDRESS" --data-urlencode "since=$since" -d timeout=30Python
import os
import time
from email.utils import parsedate_to_datetime
import requests
MAYFLY = "https://mayfly.aravaltech.com"
HEADERS = {"Authorization": f"Bearer {os.environ['MAYFLY_API_KEY']}"}
address = f"signup-{int(time.time())}@<your-name>.qa.aravaltech.info"
# 1. Mayfly's clock, before your app sends anything.
answer = requests.get(
f"{MAYFLY}/api/v1/mailboxes", params={"limit": 1}, headers=HEADERS, timeout=10
)
answer.raise_for_status()
since = parsedate_to_datetime(answer.headers["Date"]).isoformat()
# 2. Make your app send its mail to `address` here.
# 3. Wait for it.
answer = requests.get(
f"{MAYFLY}/api/v1/wait",
params={"to": address, "since": since, "timeout": 30},
headers=HEADERS,
timeout=40,
)
answer.raise_for_status()
mail = answer.json()
print(mail["otp"]["value"] if mail["otp"] else "No code in the mail")Node
Node 18 or newer, as an ES module.
const MAYFLY = "https://mayfly.aravaltech.com";
const headers = { Authorization: `Bearer ${process.env.MAYFLY_API_KEY}` };
const address = `signup-${Date.now()}@<your-name>.qa.aravaltech.info`;
// 1. Mayfly's clock, before your app sends anything.
const clock = await fetch(`${MAYFLY}/api/v1/mailboxes?limit=1`, { headers });
const since = new Date(clock.headers.get("date")).toISOString();
// 2. Make your app send its mail to `address` here.
// 3. Wait for it.
const query = new URLSearchParams({ to: address, since, timeout: "30" });
const answer = await fetch(`${MAYFLY}/api/v1/wait?${query}`, { headers });
if (!answer.ok) throw new Error(`${answer.status} ${await answer.text()}`);
const mail = await answer.json();
console.log(mail.otp?.value ?? "No code in the mail");More calls
- GET
/api/v1/messages?to=… - Mail history, newest first, without bodies.
- GET
/api/v1/messages/{id} - One mail, as the wait returns it.
- DELETE
/api/v1/mailboxes/{address} - Clear an address after a test.
- GET
/api/v1/usage - This month's mail against the plan.
- GET
/api/v1/domains - The domains and their status.