simple_email

SMTP Email Library with TLS Encryption for Eiffel

MIT License Eiffel 25.02 Design by Contract

Overview

simple_email is a production-ready SMTP email library for Eiffel with TLS encryption using native Windows SChannel (no OpenSSL dependency). It supports STARTTLS upgrade, implicit TLS (port 465), AUTH PLAIN/LOGIN authentication, and MIME multipart messages with attachments.

Part of the Simple Eiffel ecosystem.

Quick Start

Installation

  1. Set the environment variable:
    export SIMPLE_EIFFEL=/d/prod
  2. Add to your ECF file:
    <library name="simple_email" location="$SIMPLE_EIFFEL/simple_email/simple_email.ecf"/>

Send an Email

local
    email: SIMPLE_EMAIL
    msg: SE_MESSAGE
do
    create email.make

    -- Configure SMTP server
    email.set_smtp_server ("smtp.gmail.com", 587)
    email.set_credentials ("user@gmail.com", "app-password")

    -- Connect with STARTTLS
    email.connect
    email.start_tls
    email.authenticate

    -- Create message
    msg := email.create_message
    msg.set_from ("user@gmail.com")
    msg.add_to ("recipient@example.com")
    msg.set_subject ("Hello from Eiffel!")
    msg.set_text_body ("This email was sent using simple_email.")

    -- Send
    if email.send (msg) then
        print ("Email sent successfully!")
    end

    email.disconnect
end

Key Features

TLS Encryption

Native Windows SChannel - no OpenSSL dependency required.

STARTTLS Support

Upgrade plain connections to encrypted on port 587.

Implicit TLS

Direct encrypted connections on port 465.

Authentication

AUTH PLAIN and AUTH LOGIN mechanisms supported.

MIME Multipart

Text + HTML bodies and file attachments.

Security Hardened

Input validation prevents CRLF injection attacks.

API Reference

SIMPLE_EMAIL - Facade Class

Method Description
set_smtp_server (host, port) Configure SMTP server hostname and port
set_credentials (user, pass) Set authentication credentials
connect Connect to server (plain connection)
connect_tls Connect with implicit TLS (port 465)
start_tls Upgrade connection to TLS (STARTTLS)
authenticate Authenticate with stored credentials
send (message) Send email message, returns success boolean
create_message Factory for new SE_MESSAGE
disconnect Close connection

SE_MESSAGE - Email Message

Method Description
set_from (address) Set sender address (validated)
add_to (address) Add To recipient
add_cc (address) Add Cc recipient
add_bcc (address) Add Bcc recipient
set_subject (text) Set subject line
set_text_body (text) Set plain text body
set_html_body (html) Set HTML body
attach_file (path) Attach file from path
attach_data (name, type, data) Attach inline data
is_valid True if has from + recipients

Security

simple_email uses Design by Contract to enforce input validation. All email addresses must:

The library has been security hardened with:

Class Structure

Class Purpose
SIMPLE_EMAIL High-level facade for sending email
SE_MESSAGE Email message with headers, body, attachments
SE_ATTACHMENT File or inline attachment
SE_SMTP_CLIENT Full SMTP protocol implementation
SE_TLS_SOCKET WinSock + SChannel TLS socket