--- name: smtp2go-api description: Send transactional emails and SMS via SMTP2GO API. Covers authentication, /email/send and /email/mime endpoints, template management, attachments (base64/URL), webhooks for delivery events, statistics, and suppressions. Use when sending emails from Cloudflare Workers, building notifications, tracking delivery status, handling bounces. Prevents auth errors, attachment encoding issues. --- # SMTP2GO API Integration Build email and SMS delivery with the SMTP2GO transactional API. ## Quick Start ```typescript // Send email with SMTP2GO const response = await fetch('https://api.smtp2go.com/v3/email/send', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Smtp2go-Api-Key': env.SMTP2GO_API_KEY, }, body: JSON.stringify({ sender: 'noreply@yourdomain.com', to: ['recipient@example.com'], subject: 'Hello from SMTP2GO', html_body: '
Your account is ready.
', text_body: 'Welcome! Your account is ready.', }), }); const result = await response.json(); // { request_id: "uuid", data: { succeeded: 1, failed: 0, email_id: "1er8bV-6Tw0Mi-7h" } } ``` ## Base URLs | Region | Base URL | |--------|----------| | Global | `https://api.smtp2go.com/v3` | | US | `https://us-api.smtp2go.com/v3` | | EU | `https://eu-api.smtp2go.com/v3` | | AU | `https://au-api.smtp2go.com/v3` | ## Authentication Two methods supported: ```typescript // Method 1: Header (recommended) headers: { 'X-Smtp2go-Api-Key': 'your-api-key' } // Method 2: Request body body: JSON.stringify({ api_key: 'your-api-key', // ... other params }) ``` Get API keys from SMTP2GO dashboard: **Sending > API Keys** ## Core Endpoints ### Send Standard Email **POST** `/email/send` ```typescript interface EmailSendRequest { // Required sender: string; // Verified sender email to: string[]; // Recipients (max 100) subject: string; // Content (at least one required) html_body?: string; text_body?: string; // Optional cc?: string[]; // CC recipients (max 100) bcc?: string[]; // BCC recipients (max 100) reply_to?: string; custom_headers?: Array<{ header: string; value: string }>; attachments?: Attachment[]; inlines?: InlineImage[]; // Templates template_id?: string; template_data?: RecordThanks for joining {{ company }}.
', text_body: 'Welcome, {{ name }}! Thanks for joining {{ company }}.', }), }); ``` ### Send with Template ```typescript const email = { sender: 'noreply@example.com', to: ['user@example.com'], subject: 'Welcome aboard!', template_id: 'template-uuid-here', template_data: { name: 'John', company: 'Acme Corp', }, }; ``` **Template Syntax:** HandlebarsJS with `{{ variable }}` placeholders. ### Template Endpoints | Endpoint | Method | Description | |----------|--------|-------------| | `/template/add` | POST | Create new template | | `/template/edit` | POST | Update existing template | | `/template/delete` | POST | Remove template | | `/template/search` | POST | List/search templates | | `/template/view` | POST | Get template details | ## Webhooks Configure webhooks to receive real-time delivery notifications. ### Event Types **Email Events:** | Event | Description | |-------|-------------| | `processed` | Email queued for delivery | | `delivered` | Successfully delivered | | `open` | Recipient opened email | | `click` | Link clicked | | `bounce` | Delivery failed | | `spam` | Marked as spam | | `unsubscribe` | User unsubscribed | | `resubscribe` | User resubscribed | | `reject` | Blocked (suppression/sandbox) | **SMS Events:** | Event | Description | |-------|-------------| | `sending` | Processing | | `submitted` | Sent to provider | | `delivered` | Confirmed delivery | | `failed` | Delivery failed | | `rejected` | Network blocked | | `opt-out` | Recipient opted out | ### Webhook Payload (Email) ```typescript interface WebhookPayload { event: string; time: string; // Event timestamp sendtime: string; // Original send time sender: string; from_address: string; rcpt: string; // Recipient recipients: string[]; email_id: string; subject: string; bounce?: string; // Bounce type if applicable client?: string; // Email client (for opens) 'geoip-country'?: string; } ``` ### Webhook Configuration **POST** `/webhook/add` ```typescript await fetch('https://api.smtp2go.com/v3/webhook/add', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Smtp2go-Api-Key': env.SMTP2GO_API_KEY, }, body: JSON.stringify({ url: 'https://api.yourdomain.com/webhooks/smtp2go', events: ['delivered', 'bounce', 'spam', 'unsubscribe'], }), }); ``` ### Webhook Endpoints | Endpoint | Method | Description | |----------|--------|-------------| | `/webhook/view` | POST | List webhooks | | `/webhook/add` | POST | Create webhook | | `/webhook/edit` | POST | Update webhook | | `/webhook/remove` | POST | Delete webhook | **Retry Policy:** Up to 35 retries over 48 hours. Timeout: 10 seconds. ## Statistics ### Email Summary **POST** `/stats/email_summary` Combined report of bounces, cycles, spam, and unsubscribes. ```typescript const response = await fetch('https://api.smtp2go.com/v3/stats/email_summary', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Smtp2go-Api-Key': env.SMTP2GO_API_KEY, }, body: JSON.stringify({}), }); ``` ### Statistics Endpoints | Endpoint | Method | Description | |----------|--------|-------------| | `/stats/email_summary` | POST | Combined statistics | | `/stats/email_bounces` | POST | Bounce summary (30 days) | | `/stats/email_cycle` | POST | Email cycle data | | `/stats/email_history` | POST | Historical data | | `/stats/email_spam` | POST | Spam reports | | `/stats/email_unsubs` | POST | Unsubscribe data | ## Activity Search **POST** `/activity/search` (Rate limited: 60/min) Search for email events: ```typescript const response = await fetch('https://api.smtp2go.com/v3/activity/search', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Smtp2go-Api-Key': env.SMTP2GO_API_KEY, }, body: JSON.stringify({ // Filter parameters }), }); ``` **Note:** Returns max 1,000 items. For real-time data, use webhooks instead. ## Suppressions Manage email addresses that should not receive emails. ### Add Suppression **POST** `/suppression/add` ```typescript await fetch('https://api.smtp2go.com/v3/suppression/add', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Smtp2go-Api-Key': env.SMTP2GO_API_KEY, }, body: JSON.stringify({ email: 'blocked@example.com', }), }); ``` ### Suppression Endpoints | Endpoint | Method | Description | |----------|--------|-------------| | `/suppression/add` | POST | Add to suppression list | | `/suppression/view` | POST | View suppressions | | `/suppression/remove` | POST | Remove from list | ## SMS **POST** `/sms/send` ```typescript const response = await fetch('https://api.smtp2go.com/v3/sms/send', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Smtp2go-Api-Key': env.SMTP2GO_API_KEY, }, body: JSON.stringify({ to: ['+61400000000'], // Max 100 numbers message: 'Your verification code is 123456', }), }); ``` ### SMS Endpoints | Endpoint | Method | Description | |----------|--------|-------------| | `/sms/send` | POST | Send SMS | | `/sms/received` | POST | View received SMS | | `/sms/sent` | POST | View sent SMS | | `/sms/summary` | POST | SMS statistics | ## Response Codes | Code | Status | Description | |------|--------|-------------| | 200 | OK | Success | | 400 | Bad Request | Invalid parameters | | 401 | Unauthorized | Invalid/missing API key | | 402 | Request Failed | Valid params, request failed | | 403 | Forbidden | Insufficient permissions | | 404 | Not Found | Resource not found | | 429 | Too Many Requests | Rate limited | | 5xx | Server Error | SMTP2GO server issue | ### Error Response Format ```typescript interface ErrorResponse { request_id: string; data: { error: string; error_code: string; field_validation_errors?: RecordFrom: ${name} <${email}>
${message.replace(/\n/g, '
')}