dart_mail 1.0.0 copy "dart_mail: ^1.0.0" to clipboard
dart_mail: ^1.0.0 copied to clipboard

A pure Dart email stack featuring SMTP and IMAP servers, DNS MX resolution, and email relay support.

dart_mail #

pub package Null Safety GitHub Tag Last Commit License

dart_mail is a pure Dart email stack implementing SMTP, IMAP, DNS MX resolution, and email delivery.

It allows you to build a complete mail server or mail-enabled application using Dart only โ€” no external mail services required.


Overview #

dart_mail provides:

  • ๐Ÿ“ค SMTP server for receiving and relaying email
  • ๐Ÿ“ฅ IMAP server for mailbox access
  • ๐ŸŒ DNS MX resolution for remote delivery
  • ๐Ÿ—‚๏ธ Pluggable mailbox storage
  • ๐Ÿ” Authentication abstraction
  • ๐Ÿ” SMTP relay client for outbound delivery

Designed for servers, self-hosted solutions, testing environments, and embedded email infrastructure.

Add this note section to the README (fits best after Overview or Requirements):


Cross-Platform #

dart_mail runs on any operating system supported by Dart:

  • Linux
  • macOS
  • Windows
  • Docker
  • Cloud runtimes

It has no dependency on Linux-specific architectures or system services, unlike traditional SMTP/IMAP servers (Postfix, Exim, Dovecot, Sendmail).

This makes dart_mail ideal for:

  • Cross-platform development
  • Local testing on macOS or Windows
  • Containerized and embedded deployments
  • Environments where installing or managing system mail servers is not desirable

All networking, TLS, DNS resolution, and protocol handling are implemented entirely in Dart.


Features #

  • โœ‰๏ธ Fully functional SMTP server

    • Authentication
    • Local delivery
    • Remote relay via MX lookup
  • ๐Ÿ“ฌ IMAP & IMAPS servers

    • STARTTLS and TLS support
  • ๐ŸŒ DNS-over-HTTPS MX resolution

  • ๐Ÿ” Pluggable authentication providers

  • ๐Ÿ—„๏ธ Swappable mailbox storage backends

  • ๐Ÿงช Ideal for development, testing, and self-hosted setups

  • โšก 100% Dart, no native dependencies


Minimal Example #

A complete SMTP + IMAP server using in-memory storage:

import 'dart:io';

import 'package:dart_mail/dns_resolver.dart';
import 'package:dart_mail/email_delivery_client.dart';
import 'package:dart_mail/imap_server.dart';
import 'package:dart_mail/smtp_server.dart';

void main() async {
  // Simple in-memory authentication
  final authProvider = MapAuthProvider({
    'alice@example.com': 'password123',
    'bob@example.com': 'secret',
  });

  // Shared mailbox storage
  final mailboxStore = InMemoryMailboxStore(authProvider);

  // DNS resolver for MX lookups
  final dnsResolver = DNSOverHttpsResolver.google();

  // SMTP client for relaying external emails
  final emailDeliveryClient = SMTPEmailDeliveryClient(
    hostname: 'localhost',
    dnsResolver: dnsResolver,
  );

  // TLS configuration
  final securityContext = SecurityContext()
    ..useCertificateChain('certs/localhost.pem')
    ..usePrivateKey('certs/localhost.key');

  // Start SMTP server
  final smtpServer = SMTPServer(
    hostname: '0.0.0.0',
    port: 2525,
    securityContext: securityContext,
    authProvider: authProvider,
    mailboxStore: mailboxStore,
    dnsResolver: dnsResolver,
    emailDeliveryClient: emailDeliveryClient,
  );

  // Start IMAP / IMAPS server
  final imapServer = IMAPServer(
    hostname: '0.0.0.0',
    mailboxStore: mailboxStore,
    authProvider: authProvider,
    securityContext: securityContext,
    imapPort: 1143,
    imapsPort: 1993,
  );

  await smtpServer.start();
  await imapServer.start();

  print('SMTP: 2525');
  print('IMAP: 1143 (STARTTLS)');
  print('IMAPS: 1993');

  // Graceful shutdown
  ProcessSignal.sigint.watch().listen((_) async {
    await smtpServer.close();
    await imapServer.close();
    exit(0);
  });
}

Architecture #

SMTP Client
   โ”‚
   โ–ผ
SMTP Server โ”€โ”€โ–บ MailboxStore โ—„โ”€โ”€ IMAP Server
   โ”‚
   โ””โ”€โ”€โ–บ SMTP Relay โ”€โ”€โ–บ Remote MX Server
  • SMTP writes messages
  • IMAP reads messages
  • MailboxStore is the shared persistence layer
  • SMTP relay delivers messages to external domains

Use Cases #

  • Self-hosted mail servers
  • Local development mail infrastructure
  • Integration tests (email-heavy systems)
  • Custom email gateways
  • Embedded mail services in Dart backends

Requirements #

  • Dart 3.9+
  • TLS certificates (self-signed supported)
  • Open network ports for SMTP / IMAP

Issues & Feature Requests #

Please report issues and request features via the issue tracker.


Author #

Graciliano M. Passos: gmpassos@GitHub.


License #

Dart free & open-source license.

1
likes
140
points
36
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A pure Dart email stack featuring SMTP and IMAP servers, DNS MX resolution, and email relay support.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

collection, diacritic, dns_client, logging, path

More

Packages that depend on dart_mail