Getting Started with Mailtarget + OpenClaw
Send your first email in under 5 minutes.
Prerequisites
- OpenClaw installed and running
- A Mailtarget account with API access
- A verified sending domain in Mailtarget (or let the agent set one up — see Domain Setup below)
Step 1: Install the Skill
clawhub install mailtarget-email
Step 2: Get Your API Key
- Log in to app.mailtarget.co
- Go to Settings → API Keys
- Click Create API Key
- Copy the key
Step 3: Configure OpenClaw
Add your API key to the OpenClaw gateway environment:
openclaw env set MAILTARGET_API_KEY=your_api_key_here
Or export it in your shell:
export MAILTARGET_API_KEY=your_api_key_here
Step 4: Send Your First Email
Just tell your agent:
"Send a test email to hello@example.com from noreply@mydomain.com with the subject 'Hello from OpenClaw' and a simple welcome message."
The agent handles the rest — writing the HTML, calling the API, confirming delivery.
Step 5: Try More
Here are things you can ask your agent to do:
- "Send a campaign to these 50 contacts with personalized greetings" — uses substitution data
- "Create an HTML email template for our weekly newsletter" — stores it via the Template API
- "List our sending domains and check which ones are verified" — domain management
- "Send a transactional receipt email with a PDF attachment" — attachments + transactional flag
Autonomous Domain Setup (SPF / DKIM / DMARC)
🚀 Zero Manual DNS Editing
If your domain is on Cloudflare, the agent can set up email authentication entirely by itself. No DNS dashboard required.
What You Need
- Mailtarget API key (from Step 2 above)
- Cloudflare API token with DNS Write permission (create one here)
- Your Cloudflare Zone ID (found on the domain overview page)
Configure the Cloudflare credentials:
openclaw env set CLOUDFLARE_API_TOKEN=your_token_here
openclaw env set CLOUDFLARE_ZONE_ID=your_zone_id_here
Just Tell Your Agent
"Set up example.com as a sending domain in Mailtarget with full email authentication."
What the Agent Does
- Creates the sending domain in Mailtarget
- Reads the required DNS records — SPF value, DKIM selector & key, CNAME for tracking
- Adds SPF TXT record in Cloudflare (or merges into existing SPF)
- Adds DKIM TXT record in Cloudflare
- Adds CNAME record for click/open tracking
- Verifies the domain in Mailtarget
- Confirms all records pass verification
The entire process takes about 30 seconds. Fully autonomous.
For Non-Cloudflare Domains
The agent will still create the domain and read the required DNS values. It will then provide you with the exact records to add manually:
- SPF TXT record — hostname and value
- DKIM TXT record — selector hostname and public key
- CNAME record — tracking domain
After you add them, tell the agent to verify.
What's Happening Under the Hood
You (vision) → OpenClaw Agent (execution) → Mailtarget API (delivery)
- You decide what to send and who to send it to
- OpenClaw writes the content, builds the HTML, sets up domains, calls the API
- Mailtarget handles delivery, authentication (SPF/DKIM/DMARC), tracking, and reliability
Tracking & Events
Enable open and click tracking by telling your agent:
"Send the email with open tracking and click tracking enabled."
The agent sets openTracking: true and clickTracking: true in the API call. Mailtarget fires webhook events for opens, clicks, bounces, and deliveries.
Troubleshooting
| Problem | Fix |
401 Unauthorized | Check your API key is correct and active |
400 Bad Request | Verify the from email uses a verified sending domain |
| Email not arriving | Check spam folder; verify SPF/DKIM records for your domain |
MAILTARGET_API_KEY not found | Ensure the env var is set in the gateway environment |
| Domain verification fails | DNS propagation can take up to 5 minutes — tell the agent to retry |
Resources