simple_smtp

Native SMTP Email Sending for Eiffel

RFC 5321 v1.0.0 MIT

Overview

simple_smtp is a native SMTP email sending library for Eiffel. No shell commands, no curl, no external dependencies beyond EiffelNet sockets. Supports TLS, authentication, HTML emails, and attachments.

Part of the simple_* ecosystem of focused, single-purpose Eiffel libraries.

Quick Start

Installation

Add to your ECF file:

<library name="simple_smtp" location="$SIMPLE_SMTP/simple_smtp.ecf"/>

Set environment variable:

set SIMPLE_SMTP=D:\path\to\simple_smtp

Also requires: simple_base64, simple_uuid

Send an Email

local
    smtp: SIMPLE_SMTP
do
    create smtp.make ("smtp.example.com", 587)
    smtp.set_credentials ("user@example.com", "password")
    smtp.set_from ("sender@example.com", "Sender Name")
    smtp.add_to ("recipient@example.com", "Recipient")
    smtp.set_subject ("Hello from Eiffel!")
    smtp.set_body ("This is a test email.")

    if smtp.send then
        print ("Email sent!")
    else
        print ("Error: " + smtp.last_error)
    end
end

HTML Email

-- HTML only
smtp.set_html_body ("<html><body><h1>Hello!</h1></body></html>")

-- Or multipart (text + HTML fallback)
smtp.set_body_with_html (
    "Plain text for old clients",
    "<html><body><h1>HTML version</h1></body></html>"
)

With Attachments

smtp.add_attachment ("report.pdf", pdf_content, "application/pdf")
smtp.add_attachment ("data.csv", csv_content, "text/csv")

Features

Native SMTP

Pure Eiffel implementation using EiffelNet sockets. No shelling to curl or external tools.

TLS Support

STARTTLS (port 587), implicit TLS (port 465), or plain SMTP (port 25).

Authentication

AUTH LOGIN and AUTH PLAIN mechanisms with Base64 credential encoding.

Rich Content

Plain text, HTML, or multipart/alternative for email clients that prefer either.

Attachments

Add file attachments with proper MIME types and Base64 encoding.

Design by Contract

Full preconditions, postconditions, and class invariants for correctness verification.

RFC 5322 Headers

Auto-generated Date and Message-ID headers. UUID-based MIME boundaries for uniqueness.

Email Validation

Validate email addresses before sending with is_valid_email.

API Summary

Configuration

Feature Description
make (host, port) Create SMTP client for host:port
set_credentials (user, pass) Set authentication credentials
set_timeout (seconds) Set connection timeout
enable_tls Use TLS/SSL from start (port 465)
enable_starttls Upgrade to TLS via STARTTLS (port 587)

Sender & Recipients

Feature Description
set_from (email, name) Set sender (name is optional)
add_to (email, name) Add To recipient
add_cc (email, name) Add Cc recipient
add_bcc (email, name) Add Bcc recipient (not in headers)
clear_recipients Clear all recipients
set_reply_to (email, name) Set Reply-To address (name optional)
is_valid_email (address) Validate email format

Content

Feature Description
set_subject (text) Set email subject
set_body (text) Set plain text body
set_html_body (html) Set HTML body
set_body_with_html (text, html) Set multipart (text + HTML)
add_attachment (name, content, mime) Add file attachment
clear_attachments Remove all attachments

Sending & Status

Feature Description
send: BOOLEAN Send email, returns True on success
has_error: BOOLEAN Did last operation fail?
last_error: STRING Error message from last failure
last_response: STRING Last SMTP server response

View complete API reference →

Testing

The library includes a comprehensive test suite with 57 tests covering:

-- Run tests
ec.exe -batch -config simple_smtp.ecf -target simple_smtp_tests -tests