P H O T O N

CONSOLE

Loading

Developer API

How to Send Email via cURL & REST API
Bash Automation, JSON Payloads & Sub-Second Dispatch

Send transactional emails from your terminal, CI/CD pipelines, or serverless workers using standard cURL commands over HTTPS port 443.

5 min read • Sub-Second Delivery • Zero Dependencies
Direct Answer: Sending Emails via cURL

Sending emails via cURL and the HTTPS REST API eliminates the overhead of managing raw TCP SMTP sockets and local MTA daemons. With a single HTTP POST request containing a Bearer token, JSON recipient payload, and HTML body, developers achieve sub-second email dispatch suitable for CI/CD pipelines, cron jobs, and microservices over port 443.

1. Quickstart: The Minimal cURL Email Command

Execute this cURL command directly in your macOS, Linux, or Windows WSL terminal to dispatch a transactional message:

curl -X POST https://api.photonconsole.com/v1/send \ -H "Authorization: Bearer sec_live_991823ab49102c" \ -H "Content-Type: application/json" \ -d '{ "from": "billing@yourdomain.com", "to": ["user@example.com"], "subject": "Your Invoice Receipt #10492", "html": "

Thank you!

Your payment of $49.00 was successfully processed.

" }'

The API responds with an immediate JSON confirmation payload:

{ "status": "success", "message_id": "msg_01jh82390af812", "queued_at": "2026-11-16T16:55:00Z", "latency_ms": 142 }

2. Sending Rich HTML & Base64 File Attachments

Include PDF receipts, invoices, or log files by base64-encoding them in the attachments array:

# Base64 encode invoice file ATTACHMENT_DATA=$(base64 -w 0 invoice.pdf) curl -X POST https://api.photonconsole.com/v1/send \ -H "Authorization: Bearer sec_live_991823ab49102c" \ -H "Content-Type: application/json" \ -d '{ "from": "orders@yourdomain.com", "to": ["client@example.com"], "subject": "Order Confirmation & Invoice", "html": "

Please find attached your PDF invoice.

", "attachments": [ { "filename": "invoice.pdf", "content": "'"$ATTACHMENT_DATA"'", "content_type": "application/pdf" } ] }'

3. Production Bash Script with Error Handling & Retries

Wrap cURL commands in a robust shell script for automated server monitoring and backups:

#!/usr/bin/env bash set -euo pipefail API_KEY="${PHOTON_API_KEY}" RECIPIENT="$1" SUBJECT="$2" BODY="$3" RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" -X POST https://api.photonconsole.com/v1/send \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d "{ \"from\": \"alerts@yourdomain.com\", \"to\": [\"$RECIPIENT\"], \"subject\": \"$SUBJECT\", \"text\": \"$BODY\" }") STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS" | cut -d: -f2) if [ "$STATUS" -eq 200 ]; then echo "Email dispatched successfully!" else echo "Dispatch failed with HTTP status: $STATUS" exit 1 fi

5. Frequently Asked Questions

Why use the HTTPS REST API instead of raw SMTP sockets?

The HTTPS REST API operates over port 443, bypassing ISP port 25/587 firewall blocks. It is stateless, faster for serverless environments (like AWS Lambda and Cloudflare Workers), and returns structured JSON responses with immediate message tracking IDs.

Can I attach PDF documents or images using a cURL email command?

Yes. Photon Console accepts base64-encoded file strings in the attachments JSON array, including filename and MIME content_type specifications.

How do I authenticate cURL requests with Photon Console?

Include an HTTP Authorization header formatted as 'Authorization: Bearer YOUR_API_KEY' with Content-Type: application/json.

Start Sending via REST API in 2 Minutes

Get your instant API keys, explore our interactive cURL and SDK sandbox, and send 10,000 free transactional emails every month.