Karta.SMTP.Listener (Karta v1.0.0)

The configuration of one SMTP listener, and the child specs that run it: a Karta.SMTP.Limiter and a ThousandIsland server with Karta.SMTP.Handler.

Kinds:

  • :mx - inbound mail (port 25). STARTTLS offered when certificates are configured (tls: :starttls, the default) or not (tls: :none); AUTH off.
  • :submission - message submission (port 587, RFC 6409). STARTTLS required before AUTH; AUTH required before MAIL.
  • :submissions - submission over implicit TLS (port 465, RFC 8314).

The policy (Karta.SMTP.Policy) defaults by kind: Karta.SMTP.Policy.Inbound for mx (mail for the addresses that servers route, Karta.Inbound) and Karta.SMTP.Policy.Submission for the submission listeners. Karta.SMTP.Policy.Closed refuses every message.

Every listener starts in plain TCP. Implicit TLS and STARTTLS both upgrade the socket with Karta.SMTP.TLSTransport, which lets a PROXY protocol header be read before the TLS handshake and picks up reloaded certificates at every handshake.

Timeouts (milliseconds):

  • command_timeout - waiting for the next command line; RFC 5321 §4.5.3.2.7 asks for at least 5 minutes.
  • data_timeout - waiting for more DATA or BDAT bytes; RFC 5321 §4.5.3.2.6 (client side: 3 minutes per block) - 5 minutes here.
  • stress_timeout - used instead of both once the listener holds stress_threshold connections, so idle clients cannot hold every slot.
  • handshake_timeout - TLS handshake; proxy_timeout - PROXY header.
  • send_timeout - a write that cannot complete in this time closes the connection (a client that stops reading cannot block its process).
  • max_session_time - hard limit for one connection.

Memory: read_buffer caps one socket read (bytes) and max_heap_size (words, shared binaries included) caps a connection process; a process that exceeds it is killed. Line and message limits keep a correct connection far below it; the cap is a last line of defence.

Summary

Functions

The limiter and the ThousandIsland server, in start order.

The registered name of the listener's limiter (also its ETS table).

Builds and validates a listener from a keyword list. Raises on bad options.

The registered name of the listener's ThousandIsland server.

The Karta.SMTP.Session configuration for this listener.

Socket options. An IPv6 wildcard address also accepts IPv4 (dual stack).

Types

kind()

@type kind() :: :mx | :submission | :submissions

t()

@type t() :: %Karta.SMTP.Listener{
  auth: term(),
  command_timeout: term(),
  data_timeout: term(),
  dsn: term(),
  exempt: term(),
  handshake_timeout: term(),
  hostname: term(),
  ip: term(),
  kind: term(),
  limits: term(),
  max_connections: term(),
  max_heap_size: term(),
  max_per_ip: term(),
  max_session_time: term(),
  name: term(),
  num_acceptors: term(),
  policy: term(),
  policy_opts: term(),
  port: term(),
  proxy_protocol: term(),
  proxy_timeout: term(),
  rate: term(),
  rate_window: term(),
  read_buffer: term(),
  requiretls: term(),
  send_timeout: term(),
  stress_threshold: term(),
  stress_timeout: term(),
  tls: term(),
  tls_config: term(),
  trusted_proxies: term()
}

Functions

child_specs(l)

@spec child_specs(t()) :: [Supervisor.child_spec()]

The limiter and the ThousandIsland server, in start order.

limiter_name(l)

@spec limiter_name(t()) :: atom()

The registered name of the listener's limiter (also its ETS table).

new!(opts)

@spec new!(keyword()) :: t()

Builds and validates a listener from a keyword list. Raises on bad options.

server_name(l)

@spec server_name(t()) :: atom()

The registered name of the listener's ThousandIsland server.

session_config(l)

@spec session_config(t()) :: map()

The Karta.SMTP.Session configuration for this listener.

transport_options(l)

@spec transport_options(t()) :: keyword()

Socket options. An IPv6 wildcard address also accepts IPv4 (dual stack).