8 packages

Mail

Send, sign, receive, store and read email.

Overview

The packages fit together like this: net-smtp or mail-send send, mail-dkim signs, net-smtp-server receives and stores into net-mail-store, net-imap and net-pop3 give access to that store, formats-mime decodes the messages.

To send from an application through your provider, net-smtp is enough.

These are building blocks, not a complete mail server. Each server handles one connection at a time, and the SMTP server puts all received mail in a single mailbox. There is no outgoing queue, no bounce handling, and no SPF, DKIM or DMARC check of incoming mail yet. All three servers refuse passwords until the connection is encrypted.

With amc 0.8.92, a program using mail-send or net-smtp-server must be linked with libresolv (-lresolv), which these packages do not declare yet.

Send

net-smtp v0.2.7

SMTP client to send from your application through a provider: implicit TLS on port 465 or STARTTLS on 587, picked from the port. Text, HTML, attachments, Bcc, AUTH LOGIN. One visible recipient per message.

amc package add net-smtp · amalgame-lang/amalgame-net-smtp ↗

mail-send v0.4.0

Outbound delivery: to a relay (port 587, STARTTLS, AUTH PLAIN) or straight to the recipient's MX server (port 25), with optional DKIM signing. DeliverOrRelay tries direct delivery and falls back to the relay when it is refused.

amc package add mail-send · amalgame-lang/amalgame-mail-send ↗

mail-dkim v0.1.0

DKIM signing (RFC 6376, rsa-sha256, relaxed/relaxed): the DKIM-Signature header covers From, To, Subject, Date and the body. Dkim.Verify takes the key as an argument: the public key is not read from DNS yet.

amc package add mail-dkim · amalgame-lang/amalgame-mail-dkim ↗

Receive and store

net-smtp-server v0.2.2

Receiving SMTP server: EHLO, STARTTLS, AUTH PLAIN and LOGIN (scrypt-hashed passwords), MAIL, RCPT, DATA, then delivery into net-mail-store. It forwards nothing to other servers. Without authentication it refuses outside recipients and senders posing as your domain; it locks out after 5 failed logins, limits size and recipient count, and can check a DNS blocklist.

amc package add net-smtp-server · amalgame-lang/amalgame-net-smtp-server ↗

net-mail-store v0.1.0

Maildir message store with a SQLite index: atomic delivery, and per mailbox the UIDs, UIDVALIDITY, flags and sizes IMAP and POP3 need. Mailbox names are sanitized so they stay inside the account folder.

amc package add net-mail-store · amalgame-lang/amalgame-net-mail-store ↗

Read

net-imap v0.2.2

IMAP4rev1 server over net-mail-store: STARTTLS or implicit TLS (port 993), LOGIN, LIST, SELECT, FETCH, STORE, SEARCH, EXPUNGE. No IDLE, APPEND or COPY yet.

amc package add net-imap · amalgame-lang/amalgame-net-imap ↗

net-pop3 v0.2.2

POP3 server (RFC 1939) over the same store: STLS or implicit TLS (port 995), USER and PASS, STAT, LIST, UIDL, RETR, TOP, DELE.

amc package add net-pop3 · amalgame-lang/amalgame-net-pop3 ↗

formats-mime v0.1.0

RFC 5322 and MIME message reader in pure Amalgame: headers, nested multipart parts, attachments, base64, quoted-printable, RFC 2047 encoded headers. Read-only; UTF-8 and ASCII charsets.

amc package add formats-mime · amalgame-lang/amalgame-formats-mime ↗

Examples

Send from your application through your provider's SMTP server. The password comes from the SMTP_PASSWORD environment variable.

amc package add net-smtp
namespace Demo

import Amalgame.Net.Smtp

public class Program {
    public static void Main(string[] args) {
        let pass: string = Env_Get("SMTP_PASSWORD")
        // Port 587: STARTTLS; port 465: implicit TLS
        let ok: bool = Mail.New()
            .From("shop@example.com")
            .To("alice@example.com")
            .Subject("Your order")
            .Text("Thanks, it ships tomorrow.")
            .Html("<p>Thanks, it ships <b>tomorrow</b>.</p>")
            .Send("smtp.example.com", 587, "shop@example.com", pass)
        if (!ok) {
            Console.WriteLine("Not sent: " + Mail.LastError())
        }
    }
}

The whole chain on one machine, no network: build, sign, store, read back.

amc package add net-smtp
amc package add mail-dkim
amc package add net-mail-store
amc package add formats-mime
namespace Demo

import Amalgame.Net.Smtp
import Amalgame.Mail.Dkim
import Amalgame.Crypto
import Amalgame.Net.Mail
import Amalgame.Formats.Mime

public class Program {
    public static void Main(string[] args) {
        // 1. Build a message (the bytes Send would transmit)
        let raw: string = Mail.New()
            .From("shop@example.com")
            .To("alice@example.com")
            .Subject("Your order")
            .Text("Thanks, it ships tomorrow.")
            .Preview()

        // 2. Sign it with DKIM
        let key: JwsKey = JwsKey.GenerateRs256()
        let dkimMsg: string = Dkim.Sign(raw, key, "example.com", "sel1")

        // 3. Store it in a Maildir
        let store: MailStore = MailStore.Open("maildata")
        let uid: int = store.Deliver("INBOX", dkimMsg)

        // 4. Read it back and decode it
        let back: string = store.Read("INBOX", uid)
        let msg: MimePart = Mime.Parse(back)
        Console.WriteLine(msg.Subject() + ": " + msg.TextBody())
        if (Dkim.Verify(back, key)) {
            Console.WriteLine("DKIM signature valid")
        }
    }
}

At a glance

  • License: Apache-2.0
  • Install: amc package add <name> takes the latest compatible version and its dependencies
  • Versions: as listed in the registry
  • Official index: amalgame-lang/packages-index

See also