Current section
Files
Jump to
Current section
Files
src/lumenmail.erl
-module(lumenmail).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/lumenmail.gleam").
-export([smtp_builder/2, with_auth/3, with_oauth2/3, with_implicit_tls/2, with_timeout/2, allow_invalid_certs/2, connect/1, new_message/0, send/2, close/1, reset/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" LumenMail - A Gleam library for sending emails via SMTP.\n"
"\n"
" Inspired by the Rust [mail-send](https://docs.rs/mail-send/latest/mail_send/) crate.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" import lumenmail\n"
" import lumenmail/message\n"
" import lumenmail/smtp\n"
"\n"
" pub fn main() {\n"
" let email = message.new()\n"
" |> message.from_name_email(\"Sender\", \"sender@example.com\")\n"
" |> message.to_email(\"recipient@example.com\")\n"
" |> message.subject(\"Hello from Gleam!\")\n"
" |> message.text_body(\"This is a test email sent with lumenmail.\")\n"
"\n"
" let assert Ok(client) = smtp.builder(\"smtp.example.com\", 587)\n"
" |> smtp.auth(\"username\", \"password\")\n"
" |> smtp.connect()\n"
"\n"
" let assert Ok(_) = smtp.send(client, email)\n"
" let assert Ok(_) = smtp.close(client)\n"
" }\n"
" ```\n"
).
-file("src/lumenmail.gleam", 46).
?DOC(
" Creates a new SMTP client builder for the given host and port.\n"
"\n"
" Common ports:\n"
" - 25: Standard SMTP (often blocked by ISPs)\n"
" - 587: Submission with STARTTLS (recommended)\n"
" - 465: SMTPS with implicit TLS\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" let builder = lumenmail.smtp_builder(\"smtp.gmail.com\", 587)\n"
" |> lumenmail.with_auth(\"user@gmail.com\", \"app-password\")\n"
" ```\n"
).
-spec smtp_builder(binary(), integer()) -> lumenmail@smtp:smtp_client_builder().
smtp_builder(Host, Port) ->
lumenmail@smtp:builder(Host, Port).
-file("src/lumenmail.gleam", 51).
?DOC(" Adds username/password authentication to the builder.\n").
-spec with_auth(lumenmail@smtp:smtp_client_builder(), binary(), binary()) -> lumenmail@smtp:smtp_client_builder().
with_auth(Builder, Username, Password) ->
lumenmail@smtp:auth(Builder, Username, Password).
-file("src/lumenmail.gleam", 60).
?DOC(" Adds OAuth2 authentication to the builder.\n").
-spec with_oauth2(lumenmail@smtp:smtp_client_builder(), binary(), binary()) -> lumenmail@smtp:smtp_client_builder().
with_oauth2(Builder, Username, Token) ->
lumenmail@smtp:credentials(Builder, {o_auth2, Username, Token}).
-file("src/lumenmail.gleam", 69).
?DOC(" Sets implicit TLS mode (for port 465).\n").
-spec with_implicit_tls(lumenmail@smtp:smtp_client_builder(), boolean()) -> lumenmail@smtp:smtp_client_builder().
with_implicit_tls(Builder, Enabled) ->
lumenmail@smtp:implicit_tls(Builder, Enabled).
-file("src/lumenmail.gleam", 77).
?DOC(" Sets the connection timeout in milliseconds.\n").
-spec with_timeout(lumenmail@smtp:smtp_client_builder(), integer()) -> lumenmail@smtp:smtp_client_builder().
with_timeout(Builder, Timeout_ms) ->
lumenmail@smtp:timeout(Builder, Timeout_ms).
-file("src/lumenmail.gleam", 86).
?DOC(
" Allows invalid/self-signed TLS certificates.\n"
" Warning: Only use this for testing!\n"
).
-spec allow_invalid_certs(lumenmail@smtp:smtp_client_builder(), boolean()) -> lumenmail@smtp:smtp_client_builder().
allow_invalid_certs(Builder, Allow) ->
lumenmail@smtp:allow_invalid_certs(Builder, Allow).
-file("src/lumenmail.gleam", 94).
?DOC(" Connects to the SMTP server using the builder configuration.\n").
-spec connect(lumenmail@smtp:smtp_client_builder()) -> {ok,
lumenmail@smtp:smtp_client()} |
{error, lumenmail@types:smtp_error()}.
connect(Builder) ->
lumenmail@smtp:connect(Builder).
-file("src/lumenmail.gleam", 111).
?DOC(
" Creates a new empty email message builder.\n"
"\n"
" ## Example\n"
"\n"
" ```gleam\n"
" let email = lumenmail.new_message()\n"
" |> message.from_email(\"sender@example.com\")\n"
" |> message.to_email(\"recipient@example.com\")\n"
" |> message.subject(\"Hello!\")\n"
" |> message.text_body(\"Email content here.\")\n"
" ```\n"
).
-spec new_message() -> lumenmail@message:message().
new_message() ->
lumenmail@message:new().
-file("src/lumenmail.gleam", 116).
?DOC(" Sends an email using the connected client.\n").
-spec send(lumenmail@smtp:smtp_client(), lumenmail@message:message()) -> {ok,
nil} |
{error, lumenmail@types:smtp_error()}.
send(Client, Email) ->
lumenmail@smtp:send(Client, Email).
-file("src/lumenmail.gleam", 124).
?DOC(" Closes the SMTP connection.\n").
-spec close(lumenmail@smtp:smtp_client()) -> {ok, nil} |
{error, lumenmail@types:smtp_error()}.
close(Client) ->
lumenmail@smtp:close(Client).
-file("src/lumenmail.gleam", 129).
?DOC(" Resets the connection for sending another email.\n").
-spec reset(lumenmail@smtp:smtp_client()) -> {ok, nil} |
{error, lumenmail@types:smtp_error()}.
reset(Client) ->
lumenmail@smtp:reset(Client).