dart_mail 1.0.0
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 #
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.