Transactional emailUpdated · 7 min read

Email API vs SMTP: Which Should You Use?

Email API vs SMTP explained for backend engineers: what happens on the wire, why serverless runtimes struggle with SMTP, and when portability wins.

MT
Mailbase Team
email API vs SMTP
On this page · 8 sections

Overview

When your app hands an email to a provider, the recipient's inbox cannot tell whether you used an HTTP REST API or an SMTP relay. Both land on the same outbound mail servers. The difference is what happens between your backend and your provider — and on modern cloud runtimes, that difference matters far more than most tutorials mention.

What actually happens on the wire

An SMTP session is a stateful, back-and-forth conversation designed in the 1980s. Even to send a two-line password reset over port 587, your client opens a TCP socket, waits for the 220 greeting, sends EHLO, upgrades with STARTTLS, sends EHLO again, authenticates with AUTH LOGIN, sends MAIL FROM, RCPT TO, DATA, the MIME payload, . and QUIT. That is six to eight sequential network round trips before the function can return. On serverless platforms (edge workers, Lambda functions, cloud PaaS containers), outbound ports 25 and 587 are also frequently blocked or throttled, and short-lived functions cannot keep a warm SMTP connection pool alive.

An HTTP email API replaces the entire handshake with one HTTPS POST over port 443. You pass JSON, reuse standard TLS keep-alive, and get back a structured response with the provider's message ID and exact field-level error codes (422 invalid recipient, 429 rate limited) instead of parsing raw 554 SMTP strings. Even better, HTTP gives you native Idempotency-Key headers so a worker retry after a timeout never double-mails a customer.

DimensionHTTP Email APISMTP Relay (port 587 / 465)
Network round trips1 HTTPS POST over port 4436–8 sequential stateful commands
Serverless / Edge compatibilityWorks everywhere (fetch())Often blocked or high cold-start latency
Idempotency on retryNative (Idempotency-Key header)Not part of SMTP; risk of duplicate sends
Error handling & tracingJSON error codes + immediate message ID3-digit SMTP codes; coarser diagnostics
Provider portabilitySmall adapter wrapper per providerSwap host/username/password in env vars

When to pick an API — and when SMTP still wins

**Pick an HTTP API for any backend you own.** If you are sending password resets, receipts, or alerts from Node, Python, Go, or Next.js Server Actions, a thin 15-line sendEmail() wrapper around fetch() gives you better latency, cleaner logs, and idempotency — and because it sits behind one internal function, switching providers later takes an afternoon, not a rewrite.

**Pick an SMTP relay for software you do not own.** WordPress, Grafana, Keycloak, Discourse, and legacy ERP tools only accept an SMTP host, port, username, and password. You cannot rewrite their notification module to speak REST; an SMTP relay is the right tool there.

Where does Mailbase fit? Today Mailbase exposes an HTTP REST API (POST /api/v1/send with transactional: true, Idempotency-Key, and signed delivery/bounce webhooks on transactional email) and does not offer an SMTP relay yet. If you specifically need SMTP credentials for third-party apps, use Amazon SES, Resend, Postmark, or Mailgun. Whichever transport you run, deliverability comes from SPF, DKIM, and DMARC — never from the wire protocol.

  • Custom SaaS backend or serverless runtime → HTTP REST API behind a small internal helper
  • Third-party tools that only take host/port/password (Grafana, WordPress, Keycloak) → SMTP relay
  • If you use SMTP, prefer port 465 (implicit TLS) or 587 (STARTTLS) — never unencrypted port 25
  • Deliverability is identical on both; authenticate your domain and suppress hard bounces

Common mistakes

  • Sending product-critical mail and marketing from the same domain/reputation.
  • Skipping idempotency, so retries create duplicate sends.
  • Ignoring bounce and complaint webhooks until suppression breaks.
  • Treating an email API as “fire and forget” with no event logging.

Sources and further reading

Official docs for current setup details, pricing, and API behavior — verify specifics there, since they change.

Related guides

More on email api vs smtp and the surrounding transactional email workflow:

Questions

About this page.

What is the main difference between an email API and SMTP?
An email API sends a single HTTPS JSON POST over port 443 and returns a message ID, structured errors, and native idempotency. SMTP is a multi-round-trip stateful protocol over ports 587 or 465 that trades ergonomics for universal compatibility with third-party software.
Why is an email API faster than SMTP in serverless apps?
Because serverless functions rarely keep persistent TCP pools alive. SMTP pays 6 to 8 sequential round trips on every cold send, whereas an HTTP API finishes in one HTTPS POST over port 443 — and never hits blocked SMTP ports.
Does Mailbase provide an SMTP relay?
Not yet. Mailbase sends product email via its HTTP REST API (POST /api/v1/send) backed by Amazon SES in Ireland. If you need SMTP credentials for off-the-shelf software today, pair it with Amazon SES directly, Resend, Postmark, or Mailgun.
Does API vs SMTP change email deliverability?
No. Gmail, Outlook, and Apple Mail only see the message after your provider sends it out. Inbox placement depends on SPF, DKIM, DMARC alignment, domain reputation, and bounce hygiene — not how your app talked to the provider.