Karta.SMTP.Policy.Outgoing (Karta v1.0.0)

The rules of mail a server accepts for sending, whether the client authenticated with an SMTP credential (Karta.Credentials) or was identified by the address range it connected from (Karta.SMTP.Relay).

The submission listeners use this for every message. The mx listener uses it for a client an address range identified, when its policy options say ip_relay: true (KARTA_SMTP_MX_IP_RELAY); without that option the mx listener accepts no relayed mail at all.

At MAIL FROM:

  • the credential or range must still be active, and its server not suspended (550 5.7.1);
  • a range with tls_required needs a TLS connection (530 5.7.0), as AUTH does (RFC 3207);
  • the credential's rate limit (Karta.Credentials.rate_limit/1 messages a minute, counted in the database by Karta.Limits) applies; every node counts against the same limit, and a counter that cannot be read is a temporary refusal, never a bypass;
  • the envelope sender must be the null path or an address at a verified domain of the server's organisation.

At the end of data every mailbox in From and Sender must be at a verified domain (Karta.Domains.check_from/2, on parsed addresses). The message is then stored as outgoing and queued (Karta.Messages.Intake), with relay_credential_id naming the range when one let it in; recipients on the server's suppression list are recorded but not delivered to. The server's send limit and its suspension apply to delivery as they do to every outgoing message.

A database that fails gives temporary answers (451 4.3.0 at MAIL or at the end of data), never a crash and never a bypass of these rules.

Summary

Functions

Stores an outgoing message of the identified server and queues it.

Checks MAIL FROM for an identified client.

Runs fun, turning a failed database into failure instead of a crashed connection. The log line names the exception, never message data.

The session identity of a credential.

The temporary reply for a database that failed.

Functions

accept(session, spool_file)

@spec accept(Karta.SMTP.Session.t(), term()) ::
  {:ok, String.t()} | {:reject, Karta.SMTP.Reply.t()}

Stores an outgoing message of the identified server and queues it.

check_mail(session, reverse_path)

@spec check_mail(Karta.SMTP.Session.t(), :null | String.t()) ::
  :ok | {:reject, Karta.SMTP.Reply.t()}

Checks MAIL FROM for an identified client.

database(failure, fun)

@spec database(term(), (-> term())) :: term()

Runs fun, turning a failed database into failure instead of a crashed connection. The log line names the exception, never message data.

identity(credential)

@spec identity(Karta.Credentials.Credential.t()) :: map()

The session identity of a credential.

temporary()

@spec temporary() :: Karta.SMTP.Reply.t()

The temporary reply for a database that failed.