Command-line examples for retrieving emails with Mailoverse using cURL. Learn to fetch emails, parse with jq, and create polling scripts for automated testing.

cURL Examples

Basic examples for retrieving emails from the command line using cURL. Perfect for quick testing and shell scripting.

Basic Request

# Retrieve an email
curl -X GET 'https://api.mailoverse.com/email?address=test@yoursubdomain.mailoverse.com' \
  -H 'Authorization: Bearer your-api-key'

# Using environment variables
curl -X GET "https://api.mailoverse.com/email?address=test@$MAILOVERSE_DOMAIN" \
  -H "Authorization: Bearer $MAILOVERSE_API_KEY"

Parsing with jq

Use jq to extract specific fields from the response:

# Get just the subject
curl -s -X GET "https://api.mailoverse.com/email?address=test@$MAILOVERSE_DOMAIN" \
  -H "Authorization: Bearer $MAILOVERSE_API_KEY" | jq -r '.email.subject'

# Get all links from the email
curl -s -X GET "https://api.mailoverse.com/email?address=test@$MAILOVERSE_DOMAIN" \
  -H "Authorization: Bearer $MAILOVERSE_API_KEY" | jq '.email.parsedHtml.links'

# Get the first verification link
curl -s -X GET "https://api.mailoverse.com/email?address=test@$MAILOVERSE_DOMAIN" \
  -H "Authorization: Bearer $MAILOVERSE_API_KEY" | jq -r '.email.parsedHtml.links[] | select(.href | contains("verify")) | .href'

Polling Script

A bash script that polls for an email until it arrives:

#!/bin/bash
# poll-email.sh - Poll for an email until it arrives

ADDRESS=$1
TIMEOUT=${2:-30}
INTERVAL=${3:-1}

if [ -z "$ADDRESS" ]; then
  echo "Usage: poll-email.sh <email-address> [timeout] [interval]"
  exit 1
fi

START_TIME=$(date +%s)
while true; do
  CURRENT_TIME=$(date +%s)
  ELAPSED=$((CURRENT_TIME - START_TIME))

  if [ $ELAPSED -ge $TIMEOUT ]; then
    echo "Timeout waiting for email to $ADDRESS"
    exit 1
  fi

  RESPONSE=$(curl -s -X GET \
    "https://api.mailoverse.com/email?address=$ADDRESS" \
    -H "Authorization: Bearer $MAILOVERSE_API_KEY")

  if echo "$RESPONSE" | jq -e '.email != null' > /dev/null 2>&1; then
    echo "$RESPONSE" | jq '.email'
    exit 0
  fi

  sleep $INTERVAL
done

Usage:

chmod +x poll-email.sh
./poll-email.sh test@yoursubdomain.mailoverse.com 30 1

See Also