lumenmail/smtp

SMTP client implementation. Provides functionality for connecting to SMTP servers and sending emails.

Types

Active SMTP connection.

pub type SmtpClient {
  SmtpClient(
    socket: network.Socket,
    capabilities: types.ServerCapabilities,
    is_tls: Bool,
  )
}

Constructors

SMTP client configuration builder.

pub type SmtpClientBuilder {
  SmtpClientBuilder(
    host: String,
    port: Int,
    tls_mode: types.TlsMode,
    credentials: option.Option(types.Credentials),
    timeout_ms: Int,
    helo_host: String,
    allow_invalid_certs: Bool,
  )
}

Constructors

Socket type - re-exported from network module.

pub type Socket =
  network.Socket

Values

pub fn allow_invalid_certs(
  builder: SmtpClientBuilder,
  allow: Bool,
) -> SmtpClientBuilder

Allow invalid/self-signed TLS certificates.

pub fn auth(
  builder: SmtpClientBuilder,
  username: String,
  password: String,
) -> SmtpClientBuilder

Sets username/password credentials.

pub fn builder(host: String, port: Int) -> SmtpClientBuilder

Creates a new SMTP client builder.

pub fn capabilities(
  client: SmtpClient,
) -> types.ServerCapabilities

Gets server capabilities.

pub fn close(client: SmtpClient) -> Result(Nil, types.SmtpError)

Closes the SMTP connection gracefully.

pub fn connect(
  builder: SmtpClientBuilder,
) -> Result(SmtpClient, types.SmtpError)

Connects to the SMTP server.

pub fn credentials(
  builder: SmtpClientBuilder,
  creds: types.Credentials,
) -> SmtpClientBuilder

Sets authentication credentials.

pub fn helo_host(
  builder: SmtpClientBuilder,
  host: String,
) -> SmtpClientBuilder

Sets the hostname used in HELO/EHLO.

pub fn implicit_tls(
  builder: SmtpClientBuilder,
  use_implicit: Bool,
) -> SmtpClientBuilder

Sets implicit TLS mode (port 465).

pub fn noop(client: SmtpClient) -> Result(Nil, types.SmtpError)

Sends a NOOP command to keep connection alive.

pub fn reset(client: SmtpClient) -> Result(Nil, types.SmtpError)

Resets the connection state (for sending multiple emails).

pub fn send(
  client: SmtpClient,
  msg: message.Message,
) -> Result(Nil, types.SmtpError)

Sends an email message.

pub fn send_raw(
  client: SmtpClient,
  from: String,
  to: List(String),
  data: String,
) -> Result(Nil, types.SmtpError)

Sends a raw email with pre-built content.

pub fn timeout(
  builder: SmtpClientBuilder,
  timeout_ms: Int,
) -> SmtpClientBuilder

Sets connection timeout in milliseconds.

pub fn tls_mode(
  builder: SmtpClientBuilder,
  mode: types.TlsMode,
) -> SmtpClientBuilder

Sets the TLS mode.

Search Document