SMTP submission

Applications that speak SMTP send through Karta's submission listeners, with an SMTP credential of a mail server. This works with any mail library or framework that can do STARTTLS (or implicit TLS) and SMTP AUTH.

Connection settings

SettingValue
Hostthe SMTP host name of the installation (KARTA_SMTP_HOSTNAME)
Port587 with STARTTLS, or 465 with implicit TLS
AuthenticationPLAIN, LOGIN or SCRAM-SHA-256
User namethe credential's user name (8 characters, a-z and 2-7)
Passwordthe credential's password (32 characters, a-z and 2-7)
  • AUTH is offered only after TLS: before STARTTLS, AUTH gets 530 5.7.0 Must issue a STARTTLS command first.
  • MAIL FROM before AUTH gets 530 5.7.0 Authentication required.
  • TLS 1.2 or 1.3 is required (SMTP listeners).

Create a credential from the console or over the API:

{:ok, credential, password} = Karta.Credentials.create_smtp_credential(server, %{name: "Shop"})
Karta.Credentials.username(credential)
curl -s https://karta.example.com/api/v2/credentials \
  -H "Authorization: Bearer $KARTA_API_KEY" -H "Content-Type: application/json" \
  -d '{"kind": "smtp", "name": "Shop"}'
{
  "created_at": "2026-11-08T15:52:29.222633Z",
  "id": "1ed28ca1-f9a1-4907-83c5-12659a781b1c",
  "kind": "smtp",
  "name": "Shop",
  "password": "75furwdkdq5w6ttglh2qjy7ahqfdyrge",
  "prefix": "kxsxup63",
  "username": "kxsxup63"
}

The password is shown only once. Karta keeps SCRAM-SHA-256 keys (PBKDF2, 100,000 iterations, a 16-byte salt), which check PLAIN, LOGIN and SCRAM-SHA-256 alike; the password itself cannot be recovered. A revoked credential no longer authenticates, and a session that authenticated before the revocation is refused at its next MAIL FROM (550 5.7.1 Credential revoked).

Sending from an address range (no password)

A server may also accept mail from clients whose address lies in one of its IP ranges, without AUTH. This is for a machine on a network you control — an application host, an office gateway or a legacy relay — whose address is stable enough to name. Create a range credential from the server's credentials page or over the API:

curl -s https://karta.example.com/api/v2/credentials \
  -H "Authorization: Bearer $KARTA_API_KEY" -H "Content-Type: application/json" \
  -d '{"kind": "ip", "name": "Office", "cidr": "203.0.113.7/32", "tls_required": false}'
{
  "cidr": "203.0.113.7/32",
  "created_at": "2026-11-10T09:12:00.123456Z",
  "id": "018f0a5e-3f7c-7a2b-9c1d-2e3f4a5b6c7d",
  "kind": "ip",
  "name": "Office",
  "tls_required": false
}

There is no secret to show: the range itself lets the client in.

  • The range is stored in canonical form (10.20.5.9/16 becomes 10.20.0.0/16) and may be at most as wide as the instance allows: KARTA_SMTP_IP_MIN_PREFIX_V4 (default /16) and KARTA_SMTP_IP_MIN_PREFIX_V6 (default /48). The whole address space (0.0.0.0/0, ::/0) is never accepted. An IPv4-mapped IPv6 range is refused: the address is normalised to IPv4 before it is matched.
  • tls_required (default true) refuses MAIL FROM on a connection without TLS (530 5.7.0 Must issue a STARTTLS command first). Turn it off only for a client that cannot do TLS on a network you trust.
  • The client's address is the address the connection came from: the TCP peer, or the address in the PROXY protocol header of a configured trusted proxy. Nothing in a message chooses it.
  • A client in a range sends under the same rules as an authenticated one: the envelope sender and every author address must be at a verified domain of the server's organisation, the range credential's rate limit applies, and a suspended server sends nothing. The server's send limit applies to delivery as it does to all outgoing mail.
  • The most specific range wins when two servers' ranges overlap. Two active credentials cannot name the same range; revoke one before creating another for it.
  • Relayed messages are stored as outgoing with relay_credential_id naming the range, in the message API and on the message's page. Their Received: field does not claim SMTP AUTH (ESMTPA), which they did not do.

Ranges are accepted on the submission listeners (587 and 465). The mx listener accepts them only with KARTA_SMTP_MX_IP_RELAY=true, for a legacy relay that can only reach port 25; without it every client on port 25 is an ordinary mx client and gets no relay.

A connection that matches no range and has not authenticated gets 530 5.7.0 Authentication required, as before.

Examples

Ruby on Rails (config/environments/production.rb):

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: "smtp.karta.example.com",
  port: 587,
  user_name: ENV["KARTA_SMTP_USERNAME"],
  password: ENV["KARTA_SMTP_PASSWORD"],
  authentication: :plain,
  enable_starttls: true
}

Elixir with Swoosh (Swoosh.Adapters.SMTP, which needs gen_smtp):

config :my_app, MyApp.Mailer,
  adapter: Swoosh.Adapters.SMTP,
  relay: "smtp.karta.example.com",
  port: 587,
  username: System.fetch_env!("KARTA_SMTP_USERNAME"),
  password: System.fetch_env!("KARTA_SMTP_PASSWORD"),
  tls: :always,
  auth: :always

Python (smtplib):

import smtplib, ssl

with smtplib.SMTP("smtp.karta.example.com", 587) as s:
    s.starttls(context=ssl.create_default_context())
    s.login(username, password)
    s.send_message(message)

The Rails and Swoosh snippets use those libraries' ordinary SMTP options; check them against the version you use. Karta needs nothing special from a client beyond TLS and AUTH.

What happens to a message

  1. At MAIL FROM Karta checks that the credential is still active, that its server is not suspended, the credential's rate limit, and that the envelope sender is empty (<>) or at a verified domain of the organisation.
  2. Every RCPT TO is accepted (up to 100 per message).
  3. After the data, Karta checks the header: exactly one From, at most one Sender, a Sender when From has several mailboxes, and every one of those mailboxes at a verified domain.
  4. The message is stored and queued, and only then does Karta answer 250 2.0.0 OK queued as <message id>.

The message is stored exactly as received, with Karta's Received: field in front, for example:

Received: from client.example.org ([192.0.2.1])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384)
	by smtp.karta.example.com with ESMTPSA id 0193...
	for <bob@example.net>; Sat, 07 Nov 2026 12:00:00 +0000

Karta does not add Date, Message-ID or other fields to a submitted message, and does not rewrite it apart from tracking and signing at delivery. The HELO name is written only when it is a valid domain name or address literal, and the recipient only when there is exactly one.

Replies you may see

ReplyWhen
250 2.0.0 OK queued as <id>stored and queued; <id> is the message id in every API
450 4.7.1 Sending rate limit exceeded, try again laterthe credential's limit (messages per minute)
451 4.3.0 Temporary failure, try again laterthe database failed
451 4.3.0 Temporary storage failure, try again laterstoring the message failed
454 4.7.0 Temporary authentication failurethe credential store was unavailable
530 5.7.0 Authentication requiredMAIL FROM without AUTH, from an address in no range
530 5.7.0 Must issue a STARTTLS command firsta range with tls_required on a connection without TLS
535 5.7.8 Authentication credentials invalidwrong user name or password (after 3 failures: 421 4.7.0)
550 5.7.1 Sender address not permittedthe envelope sender is not at a verified domain
550 5.7.1 From or Sender address not permittedan author address is not at a verified domain
550 5.6.0 Message has no From field (and similar)the header's author fields are malformed
550 5.7.1 Sending is suspended for this serverthe server is suspended
550 5.7.1 Credential revokedthe credential was revoked during the session
552 5.3.4 Message size exceeds fixed maximum message sizelarger than 25 MiB
554 5.6.0 Message contains bare <CR> or <LF>a line ending other than CRLF in the data

The full list is in SMTP replies and status codes.

REQUIRETLS

A message that must never cross a hop in clear or to an unauthenticated server is submitted with REQUIRETLS on MAIL FROM (RFC 8689), after STARTTLS:

MAIL FROM:<ann@example.org> REQUIRETLS

Karta then delivers it only over verified TLS to an authenticated MX host that supports REQUIRETLS, and passes the requirement on; otherwise the recipient bounces with 5.7.30, and the delivery status notification carries only the message's header (Delivery).

The opposite, a message that should be delivered even where the recipient's TLS policies would stop it (to report a broken certificate, for example), carries the header field TLS-Required: No.

Internationalised mail

SMTPUTF8 and 8BITMIME are supported: UTF-8 addresses need SMTPUTF8 on MAIL FROM (otherwise 5.6.7), and Karta keeps the message as received. When the recipient's server does not offer what a message needs, the recipient bounces (see Delivery).