smtp
| Kind | ffi-zig |
|---|---|
| Capabilities | ffi net |
| Categories | network email ffi |
| Keywords | smtp email mail zig-ffi |
SMTP email client for Kit using native Zig FFI
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
examples/basic.kit | Basic offline usage example |
examples/error-handling.kit | Typed SMTP error handling example |
examples/raw-message.kit | Raw message and envelope example |
kit.toml | Package manifest with metadata and dependencies |
src/smtp.kit | SMTP error type for typed error handling. |
tests/smtp.test.kit | Tests for smtp |
zig/kit_ffi.zig | Zig FFI module for kit ffi |
zig/smtp.zig | Zig FFI module for smtp |
Dependencies
No Kit package dependencies.
This package uses native Zig FFI and requires the ffi and net capabilities
for SMTP connections.
Installation
kit add gitlab.com/kit-lang/packages/kit-smtp.gitUsage
import Kit.Smtp as SMTP
main = fn =>
result = SMTP.send {
host: "smtp.example.com",
port: 25,
sender: "sender@example.com",
to: "recipient@example.com",
subject: "Hello from Kit",
body: "This message was sent from Kit.",
}
match result
| Ok _ -> println "Email sent"
| Err err -> println "SMTP failed: ${show err}"
mainManual SMTP sessions are also supported:
import Kit.Smtp as SMTP
main = fn =>
match SMTP.connect "smtp.example.com" 25
| Err err -> println "Connect failed: ${show err}"
| Ok conn ->
defer SMTP.quit conn
SMTP.mail-from conn "sender@example.com"
SMTP.rcpt-to conn "recipient@example.com"
SMTP.data conn "Subject: Hello\r\n\r\nMessage body"
mainSMTP.send accepts a record with:
| Field | Required | Description |
|---|---|---|
host | yes | SMTP server hostname |
sender | yes | Envelope sender address |
to | yes | Envelope recipient address |
port | no | SMTP server port, defaults to 25 |
subject | no | Message subject |
body | no | Message body |
username | no | SMTP username |
password | no | SMTP password |
SMTP Notes
SMTP.send performs the full SMTP flow: connect, optional authentication,
MAIL FROM, RCPT TO, DATA, and QUIT.
For manual sessions, SMTP.connect performs the initial server greeting and
EHLO handshake. Use SMTP.auth for AUTH LOGIN or SMTP.auth-plain for AUTH
PLAIN when your server supports authentication on the active connection.
SMTP.send-raw expects an envelope string in "from@example.com,to@example.com"
format and message data that already contains the headers and body.
The current native implementation uses plain TCP SMTP. STARTTLS and SMTPS are
not implemented in this package.
Development
Running Examples
Run examples with the interpreter:
kit run examples/basic.kit
kit run examples/error-handling.kit
kit run examples/raw-message.kitCompile an example to a native binary:
kit build examples/basic.kit && ./basicThe checked-in examples are offline and deterministic so they can run in
parity checks without a live SMTP server.
Running Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow (format, check, test):
kit devThis will:
- Format and check source files in
src/ - Type check examples in
examples/ - Run tests in
tests/with coverage
Running Parity Checks
Run interpreter/compiler parity checks for examples:
kit parity --failures-onlyGenerating Documentation
Generate API documentation from doc comments:
kit docNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html.
Cleaning Build Artifacts
Remove generated files, caches, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis installs the package to ~/.kit/packages/@kit/smtp/, making it available
for import as Kit.Smtp in other projects.
License
This package is released under the MIT License - see LICENSE for details.
Exported Functions & Types
SMTPError
SMTP error type for typed error handling. Variants distinguish between different failure modes.
Variants
SMTPConnectionError {message}SMTPAuthError {message}SMTPSendError {message}SMTPProtocolError {message}