All articles SMTP & Infrastructure

Email API Integration: A Developer's Guide to Sending Transactional Email Programmatically

SSam wallness07 Jul 2026
Email API Integration: A Developer's Guide to Sending Transactional Email Programmatically

Building transactional email into an application used to mean running your own mail server or wiring up raw SMTP authentication in code. Email APIs changed that. Today, sending a password reset or order confirmation is an HTTP request — post a JSON payload to an endpoint and the infrastructure handles the rest.

But using an email API correctly is more than making requests that return a 200. Deliverability, error handling, webhook integration, and domain authentication all matter if your transactional email is going to behave reliably at scale. This guide covers the fundamentals.

How Email APIs Work

An email API is a REST interface provided by a sending platform. Instead of configuring an SMTP connection in your code, you make an HTTP POST request with your email content, recipients, and credentials. The platform handles SMTP delivery, queuing, retries, and reporting. A basic request looks something like this:

POST https://api.mailprovider.com/v1/send
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY

{
  "from": "noreply@yourapp.com",
  "to": ["user@example.com"],
  "subject": "Your order has shipped",
  "html": "Your order is on its way.",
  "text": "Your order is on its way."
}

The API returns an HTTP response with a message ID and status. From there, you use webhooks to receive delivery events asynchronously.

Authentication and Domain Setup

Before sending a single message, two things need to be correct: API authentication and domain verification.

API keys authenticate your application to the email provider. Best practices here:

  • Store keys in environment variables, never hardcoded in source code
  • Scope keys to the minimum necessary permissions — send-only, not admin
  • Rotate keys regularly and revoke any that are unused
  • Use separate keys for development, staging, and production environments

Domain verification requires adding DNS records — SPF, DKIM, and sometimes CNAME records — to authorize the email provider to send from your domain. Without domain verification, messages will either fail authentication checks or send using the provider's own domain in the Return-Path, which limits deliverability. For teams using MailDog's SMTP and email sending infrastructure, domain setup instructions are in the documentation.

Always Include Both HTML and Plain Text

The API will let you send HTML-only messages. Do not. Always include a plain text version alongside your HTML:

  • Some email clients or environments display only plain text
  • Messages without a text part score slightly higher in spam filters
  • Most legitimate email includes both — omitting plain text is a minor but real signal

Handling API Errors Correctly

Email API calls fail. Networks drop, rate limits kick in, and invalid addresses slip through. How you handle failures determines whether transactional email is reliable or silently lossy.

HTTP status codes from email APIs follow standard conventions. 2xx responses mean the message was accepted for delivery — not that it was delivered, just queued. 4xx responses are client errors: bad request format, invalid API key, or unverified sending domain. Do not retry 4xx responses automatically — fix the issue in code first. 5xx responses are server errors and are safe to retry with exponential backoff.

Implement retry logic for 5xx responses with increasing delays between attempts. Three retries with delays of 1, 2, and 4 seconds covers most transient failures without overwhelming the API.

Webhooks: Tracking What Happens After You Send

The API response confirms the message was accepted. Delivery, bounces, complaints, and unsubscribes happen later. Webhooks capture those events by sending POST requests to your endpoint when they occur.

Events you should handle in your webhook processor:

  • delivered: The receiving server accepted the message
  • hard bounce: The address is invalid — remove it from your system immediately and never send to it again
  • soft bounce: Temporary delivery failure — the provider will retry, but log it for monitoring
  • spam complaint: The recipient marked the message as spam — suppress future sends to this address
  • unsubscribe: The recipient unsubscribed — honor it immediately in your database

Hard bounces and spam complaints are especially important. Continuing to send to invalid addresses or to recipients who complained harms your sender reputation and can lead to blocklisting.

Rate Limits and Sending at Scale

Email APIs enforce rate limits — typically messages per second or per minute. At low volume this rarely matters. At scale you need to queue messages on your side or use batch sending endpoints your provider supports. Build your sending queue with rate limit awareness from the start rather than retrofitting it later when volume grows.

Testing Before Production

Before going live, test the full integration:

  • Send test messages and verify they render correctly across Gmail, Outlook, and Apple Mail
  • Check headers of received messages to confirm SPF and DKIM are passing
  • Use the provider's sandbox mode to test bounce and complaint webhook handling
  • Verify webhook events are being received and the correct database actions are triggered

A reliable transactional email integration handles the full lifecycle — sending, delivery confirmation, bounce suppression, and complaint handling. For documentation on the MailDog email API and SMTP infrastructure, see the developer docs. To evaluate plans and volume tiers, visit the pricing page. For questions about your specific integration, reach out to the team.

Related articles

Transactional Email Infrastructure Design: Building for Reliability at Scale
SMTP & Infrastructure
Sam wallness

Transactional Email Infrastructure Design: Building for Reliability at Scale

Transactional email has fundamentally different infrastructure requirements from marketing campaigns — it needs to be fast, reliable, and completely isolated from anything that could drag down its deliverability. This guide covers the architecture decisions that matter: queue design, authentication, suppression lists, monitoring, and how to test before you go live.

Read article
SMTP Server Hardening: Locking Down Your Mail Transfer Agent
SMTP & Infrastructure
Sam wallness

SMTP Server Hardening: Locking Down Your Mail Transfer Agent

A misconfigured SMTP server can be exploited as an open relay, used to send spam from your domain, or damage your sending reputation in ways that take weeks to repair. This practical hardening checklist covers open relay prevention, TLS enforcement, rate limiting, authentication requirements, and the ongoing monitoring that keeps your mail server secure long-term.

Read article