lumenmail
LumenMail - A Gleam library for sending emails via SMTP.
Inspired by the Rust mail-send crate.
Example
import lumenmail
import lumenmail/message
import lumenmail/smtp
pub fn main() {
let email = message.new()
|> message.from_name_email("Sender", "sender@example.com")
|> message.to_email("recipient@example.com")
|> message.subject("Hello from Gleam!")
|> message.text_body("This is a test email sent with lumenmail.")
let assert Ok(client) = smtp.builder("smtp.example.com", 587)
|> smtp.auth("username", "password")
|> smtp.connect()
let assert Ok(_) = smtp.send(client, email)
let assert Ok(_) = smtp.close(client)
}
Values
pub fn allow_invalid_certs(
builder: smtp.SmtpClientBuilder,
allow: Bool,
) -> smtp.SmtpClientBuilder
Allows invalid/self-signed TLS certificates. Warning: Only use this for testing!
pub fn close(
client: smtp.SmtpClient,
) -> Result(Nil, types.SmtpError)
Closes the SMTP connection.
pub fn connect(
builder: smtp.SmtpClientBuilder,
) -> Result(smtp.SmtpClient, types.SmtpError)
Connects to the SMTP server using the builder configuration.
pub fn new_message() -> message.Message
Creates a new empty email message builder.
Example
let email = lumenmail.new_message()
|> message.from_email("sender@example.com")
|> message.to_email("recipient@example.com")
|> message.subject("Hello!")
|> message.text_body("Email content here.")
pub fn reset(
client: smtp.SmtpClient,
) -> Result(Nil, types.SmtpError)
Resets the connection for sending another email.
pub fn send(
client: smtp.SmtpClient,
email: message.Message,
) -> Result(Nil, types.SmtpError)
Sends an email using the connected client.
pub fn smtp_builder(
host: String,
port: Int,
) -> smtp.SmtpClientBuilder
Creates a new SMTP client builder for the given host and port.
Common ports:
- 25: Standard SMTP (often blocked by ISPs)
- 587: Submission with STARTTLS (recommended)
- 465: SMTPS with implicit TLS
Example
let builder = lumenmail.smtp_builder("smtp.gmail.com", 587)
|> lumenmail.with_auth("user@gmail.com", "app-password")
pub fn with_auth(
builder: smtp.SmtpClientBuilder,
username: String,
password: String,
) -> smtp.SmtpClientBuilder
Adds username/password authentication to the builder.
pub fn with_implicit_tls(
builder: smtp.SmtpClientBuilder,
enabled: Bool,
) -> smtp.SmtpClientBuilder
Sets implicit TLS mode (for port 465).
pub fn with_oauth2(
builder: smtp.SmtpClientBuilder,
username: String,
token: String,
) -> smtp.SmtpClientBuilder
Adds OAuth2 authentication to the builder.
pub fn with_timeout(
builder: smtp.SmtpClientBuilder,
timeout_ms: Int,
) -> smtp.SmtpClientBuilder
Sets the connection timeout in milliseconds.