Mailcub logo
Back to Documentation

Sending Emails

Learn how to send emails using the MailCub API with code examples in multiple languages.

Quick Start

Before You Begin

  • You have a MailCub account and API key
  • Your domain is verified and configured
  • You have a valid sender email address

API Endpoint

POST
https://api.mailcub.com/v1/send

Code Examples

curl -X POST https://api.mailcub.com/v1/send \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "recipient@example.com",
    "from": "sender@yourdomain.com",
    "subject": "Welcome to our service!",
    "html": "<h1>Welcome!</h1><p>Thanks for signing up.</p>",
    "text": "Welcome! Thanks for signing up."
  }'

Request Parameters

ParameterTypeRequiredDescription
tostringYesRecipient email address
fromstringYesSender email address (must be verified)
subjectstringYesEmail subject line
htmlstringNoHTML email content
textstringNoPlain text email content
reply_tostringNoReply-to email address
tagsarrayNoTags for categorizing emails

Response Format

Success Response (200)
{
  "id": "msg_1234567890abcdef",
  "status": "queued",
  "message": "Email queued for delivery",
  "created_at": "2025-01-15T10:30:00Z"
}

Error Handling

Common Error Codes

  • 400: Bad Request - Invalid parameters
  • 401: Unauthorized - Invalid API key
  • 403: Forbidden - Sender not verified
  • 429: Rate Limited - Too many requests
  • 500: Server Error - Internal server error
Error Response (400)
{
  "error": {
    "code": "invalid_parameter",
    "message": "The 'to' field is required",
    "details": {
      "field": "to",
      "reason": "missing_required_field"
    }
  }
}

Best Practices

✅ Do

  • • Always include both HTML and text versions
  • • Use descriptive subject lines
  • • Verify sender domains before sending
  • • Handle API errors gracefully
  • • Use tags for better organization
  • • Implement retry logic for failed requests

❌ Don't

  • • Send emails from unverified domains
  • • Use misleading subject lines
  • • Send unsolicited emails (spam)
  • • Ignore rate limits
  • • Hard-code API keys in client-side code
  • • Send emails without proper error handling

Next Steps

Now that you know how to send emails, explore these advanced features: