# SMTP vs API: Which to Use for Sending Email

> SMTP vs API for sending email: how each works, setup, errors, retries, speed and deliverability compared, and what moving from SMTP to an email API looks like.

Canonical: https://www.cresca.xyz/blog/smtp-vs-api-sending
Author: Lalit Kumar Jangid
Published: 2026-08-31
Last updated: 2026-10-27

**SMTP vs API** is the first choice you make when your app needs to send email. SMTP is the standard protocol every mail server speaks: your code opens a connection, logs in and hands over a message. An email API is an HTTPS endpoint from your email provider: your code sends one JSON request and gets back an id. Both deliver to the same inboxes. They differ in setup, error handling, retries, speed and how easily you can switch providers. This guide compares them honestly and shows what moving from SMTP to an API looks like in code.

**TL;DR**

- SMTP: works with almost any existing software and library, and switching providers means changing credentials. Errors are terse and retries can duplicate email.
- API: one HTTPS request, JSON errors with stable names, idempotency keys for safe retries, batches, templates and scheduling. The request format is provider-specific.
- Deliverability is the same either way: it depends on your domain authentication, reputation and content, not the protocol.
- Cresca sends through its HTTP API today. An SMTP relay is on the roadmap.

## SMTP vs API: the short answer

Use SMTP when the software sending the email only has SMTP settings, such as an off-the-shelf app, a plugin or a device you cannot change, or when you want to swap providers without touching code. Use an API when you write the code that sends the email: you get clearer errors, safe retries, fewer round trips and features SMTP has no place for.

## How SMTP sending works

SMTP (Simple Mail Transfer Protocol) is a conversation between your app and a mail server. For each connection the client says hello (`EHLO`), upgrades to TLS (`STARTTLS`), authenticates (`AUTH`), then for each message names the sender (`MAIL FROM`), each recipient (`RCPT TO`) and sends the raw MIME message (`DATA`). Your library builds the MIME message: headers, the plain-text and HTML parts, attachments.

Submission happens on port 587 (STARTTLS) or 465 (implicit TLS). Port 25 is for server-to-server delivery, and many cloud providers block or restrict outbound traffic on it. Every step is a network round trip, so libraries keep connections open and pool them for volume.

## How an email API works

An email API replaces that conversation with one HTTPS request. With Cresca you `POST` JSON to `https://api.cresca.xyz/api/v1/emails` with your API key as a bearer token, and get `{"id": "..."}` back within milliseconds. The provider builds the MIME message, signs it with DKIM for your verified domain and delivers it.

```bash
curl https://api.cresca.xyz/api/v1/emails \
  -H "Authorization: Bearer $CRESCA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: welcome/user-123" \
  -d '{
    "from": "Acme <hello@acme.com>",
    "to": "ana@example.com",
    "subject": "Welcome to Acme",
    "html": "<p>Hi Ana, your account is ready.</p>"
  }'
```

## SMTP vs API compared

|  | SMTP | Email API |
| --- | --- | --- |
| Setup | Host, port, username and password in your app's mail settings | An API key and an HTTP client |
| Code changes to adopt | Often none: most frameworks and apps already support SMTP | Replace the send call with an HTTP request |
| Switching providers | Change the credentials | Change the request format and endpoint |
| Round trips per message | Several (hello, TLS, auth, sender, each recipient, data) | One request; up to 100 emails with batch sending |
| Errors | Three-digit reply codes with free-text messages | HTTP status plus a JSON body with a stable error name |
| Safe retries | No standard way; a retry after a dropped connection can send twice | An `Idempotency-Key` header returns the first result instead of sending again |
| Templates, scheduling, tags | Not part of the protocol; provider-specific headers if offered | Fields in the request, such as a template alias with variables or a send time |
| Network requirements | Outbound port 587 or 465 | Outbound HTTPS on port 443 |
| Message id for tracking | Depends on the provider's reply text | Returned in the response, used to look up delivery status |

## When SMTP is the better choice

- The sending software only offers SMTP settings: a CMS plugin, a helpdesk, a printer or scanner, a self-hosted app you do not maintain.
- You have a large codebase built on a mail library and no time to change the send path.
- You want to move between providers often, and a credentials change is all you want to touch.

## When an API is the better choice

- You write the code that sends the email, for example password resets, receipts or notifications from your app.
- You need to know exactly what failed and branch on it: an invalid sender, a missing template variable, a rate limit or a used-up allowance each have their own name. See [API errors](https://www.cresca.xyz/docs/errors).
- You retry on failure and must never send a receipt twice. See [idempotency](https://www.cresca.xyz/docs/idempotency).
- You run in serverless functions or containers, where opening SMTP connections per request is slow and outbound mail ports may be restricted.
- You want templates with variables, scheduled sends up to 30 days ahead, or tags on each email, all as request fields. See the [send email API guide](https://www.cresca.xyz/blog/send-email-api).

## Does SMTP or an API affect deliverability?

No. Mailbox providers see the same message either way. Whether it reaches the inbox depends on SPF, DKIM and DMARC for your sending domain, your domain and IP reputation, your complaint and bounce rates, and your content. Gmail and Yahoo require that authentication from bulk senders; the [Gmail and Yahoo sender requirements](https://www.cresca.xyz/blog/gmail-yahoo-sender-requirements) checklist covers it. The protocol only changes how your app hands the message to the provider.

## Does Cresca support SMTP?

Not yet. Cresca sends transactional email through its HTTP API, and an SMTP relay is on the roadmap. Marketing campaigns are built and sent in the Cresca app, so they need neither. If you are writing the integration yourself, the API is the faster path today: verify a domain, create a sending-access key and send, as described in the [quickstart](https://www.cresca.xyz/docs/quickstart).

## Moving from SMTP to an API: before and after

Here is the same email in Python, first with `smtplib` and then with the Cresca API. The SMTP version builds the MIME message and drives the protocol; the API version describes the email and lets the provider do the rest.

```python
# Before: SMTP with smtplib
import os
import smtplib
from email.message import EmailMessage

msg = EmailMessage()
msg["From"] = "Acme <hello@acme.com>"
msg["To"] = "ana@example.com"
msg["Subject"] = "Welcome to Acme"
msg.set_content("Hi Ana, your account is ready.")
msg.add_alternative("<p>Hi Ana, your account is ready.</p>", subtype="html")

with smtplib.SMTP("smtp.example.com", 587, timeout=10) as smtp:
    smtp.starttls()
    smtp.login("apikey", os.environ["SMTP_PASSWORD"])
    smtp.send_message(msg)
```

```python
# After: the Cresca email API with requests
import os
import requests

res = requests.post(
    "https://api.cresca.xyz/api/v1/emails",
    headers={
        "Authorization": f"Bearer {os.environ['CRESCA_API_KEY']}",
        "Idempotency-Key": "welcome/user-123",
    },
    json={
        "from": "Acme <hello@acme.com>",
        "to": "ana@example.com",
        "subject": "Welcome to Acme",
        "html": "<p>Hi Ana, your account is ready.</p>",
    },
    timeout=10,
)
body = res.json()
if not res.ok:
    raise RuntimeError(f"{body['name']}: {body['message']}")
print(body["id"])
```

When you migrate a real app, work through this list:

1. **Verify your sending domain** with the new provider and add its DNS records before switching traffic. See [Sending Domains](https://app.cresca.xyz/sending-domains).
2. **Map the fields.** From, To, Cc, Bcc, Reply-To, Subject, the text and HTML parts and attachments (as base64) all have request fields. Custom headers such as `List-Unsubscribe` go in `headers`.
3. **Add idempotency keys** built from the event, such as `receipt/order-1042`, so retries are safe.
4. **Retry only what is worth retrying:** network errors, timeouts, `429` and `5xx`, with backoff. Fix other `4xx` errors instead.
5. **Use batch sending** for volume: up to 100 emails per request. Requests per second depend on your plan; see [rate limits](https://www.cresca.xyz/docs/rate-limits).
6. **Store the returned id** next to the record that triggered the email, so you can look up its delivery status later.

## Send email API tutorials by language

Each tutorial has a copy-paste client with retries and idempotency, plus templates, attachments and batches:

- [Send email with Node.js](https://www.cresca.xyz/blog/send-email-nodejs)
- [Send email with Python](https://www.cresca.xyz/blog/send-email-python)
- [Send email with PHP](https://www.cresca.xyz/blog/send-email-php)
- [Send email with Go](https://www.cresca.xyz/blog/send-email-golang)
- [Send email with Ruby](https://www.cresca.xyz/blog/send-email-ruby)
- [Send email with Java](https://www.cresca.xyz/blog/send-email-java)
- [Send email with C# and .NET](https://www.cresca.xyz/blog/send-email-csharp)
- [Send email with Next.js](https://www.cresca.xyz/blog/send-email-nextjs)
- [Send email with Laravel](https://www.cresca.xyz/blog/send-email-laravel)
- [Send email with Django](https://www.cresca.xyz/blog/send-email-django)
- [Send email with Ruby on Rails](https://www.cresca.xyz/blog/send-email-rails)

## Frequently asked questions

### What is the difference between SMTP and an email API?

SMTP is the standard mail protocol: your app opens a connection to a mail server, authenticates and transfers a MIME message step by step. An email API is an HTTPS endpoint from your provider: your app sends one JSON request describing the email and gets back an id, and the provider builds and delivers the message.

### Is an email API faster than SMTP?

Usually, for your application. An API send is one HTTPS request, while SMTP needs several round trips per connection and per message, and batch APIs carry up to 100 emails in one request. Delivery time to the inbox after the provider accepts the email is about the same.

### Is SMTP more reliable than an API?

Neither is more reliable at delivering email. The difference is in failure handling: an API returns structured errors and supports idempotency keys, so a retry after a timeout cannot send a duplicate. With SMTP, a connection that drops after the data was sent leaves you unsure whether to retry.

### Which ports does SMTP use?

Port 587 with STARTTLS and port 465 with implicit TLS are for submitting email from an app. Port 25 is for server-to-server delivery and is often blocked by cloud providers. An email API uses HTTPS on port 443, which is almost never blocked.

### Can I use SMTP with Cresca?

Not yet. Cresca sends through its HTTP API today, and an SMTP relay is on the roadmap. The API works from any language that can make an HTTPS request, and the tutorials above cover the most common stacks.

## Start sending

Verify a domain, create a sending-access key and make your first API call in a few minutes. **[Try Cresca free for 30 days](https://app.cresca.xyz/signup)**, no credit card required, then follow the [quickstart](https://www.cresca.xyz/docs/quickstart).
