gsmtp

SMTP Client for Gleam

Package Version Hex Docs

Further documentation can be found at https://hexdocs.pm/gsmtp.

RFC

Current state

A simple mail to a SMTP server can be sent

Use it like this

gleam add gsmtp
import gsmtp/builder
import gsmtp/smtp
import logging

pub fn main() {
  logging.configure()
  logging.set_level(logging.Debug)

  let message =
    builder.new_builder()
    |> builder.from_email("send@gleam.com")
    |> builder.to_emails(["receive@gleam.com"])
    |> builder.subject("Test Gleam E-Mail")
    |> builder.body("Mail from Gleam")
    |> builder.create()

  let auth = Some(#("testuser", "start123"))

  let assert Ok(Nil) =
    smtp.send(host: "127.0.0.1", port: 2525, auth: auth, message: message)
}

TODO

Development

Use smtp4dev as a dev SMTP server

docker compose up

Make sure to setup postfix to send mails only locally

For just simple SMTP command tests you can use telnet

telnet localhost 2525

and run the following commands

HELO localhost
MAIL FROM:<sender@example.com>
RCPT TO:<user@localhost>
DATA
Subject: Test Email
From: sender@example.com
To: user@localhost

This is a test email sent manually.

.
QUIT

This is basically what the library does. it opens a TCP connection and runs the commands

To test the gleam smtp client run

gleam test

This project is inspired by the go smtp package

Thats why there is a working smtp client in the go/ directory.

Run it with

go run go/main.go
Search Document