How martinstromberg/gabriel works
Project type and purpose
• Gabriel is a standalone email server implemented in Go. Its primary functions are to accept incoming SMTP connections (receiving email) and to relay or send outgoing email to remote SMTP servers.
• This is a backend/network service, not a full-stack web application or GUI tool.
File structure
• cmd/gabrield.go: the main entry point that initializes and runs the server.
• internal/network: low-level TCP client and listener abstractions.
• internal/server: server configuration and the SMTP protocol handler.
• internal/submission: the SMTP “submission” functionality (SMTP verbs like HELO, AUTH, MAIL FROM, RCPT TO, DATA, STARTTLS, etc.), organized by concern (authentication, commands, data handling, recipient/sender logic).
• No frontend; no database subfolder—state is likely held in memory.
README
• Confirms that Gabriel’s goal is bidirectional email handling (send & receive).
• Mentions support for LOGIN and PLAIN authentication, potential future GSSAPI.
Main components
a. TCP Listener
• Accepts inbound connections on port 25 (or 587).
• Provided by internal/network/tcp_listener.go.
b. SMTP Protocol Handler
• Parses SMTP commands, manages session state.
• Located in internal/server/smtp.go, internal/server/config.go.
c. Submission Modules
• Authentication (LOGIN, PLAIN) – internal/submission/authentication.go
• Command handlers (HELO/EHLO, MAIL, RCPT, DATA) – internal/submission/*.go
• STARTTLS negotiation – internal/submission/start_tls.go
• Data and envelope processing – internal/submission/data.go, recipient.go, sender.go.
d. Network Client
• For outbound email delivery (acts as SMTP client) – internal/network/tcp_client.go.
e. Configuration
• Server options (ports, timeouts) – internal/server/config.go.
f. External Dependencies
• DNS for MX lookup (implicit or via Go stdlib).
• TLS libraries (Go crypto/tls).
Interactions and data flow
1. Client (external SMTP client or another mail server) → TCP Listener
2. TCP Listener → SMTP Protocol Handler
3. SMTP Handler → Submission Modules
• AUTH module verifies credentials
• MAIL/RCPT track envelope
• DATA module buffers message
• STARTTLS triggers TLS handshake
4. On successful DATA completion:
• Submission Module invokes Network Client
• Network Client resolves MX via DNS
• Network Client makes outbound TCP → remote SMTP server
5. Server responds back to original client with success/failure codes.
Architectural patterns and design principles
• Layered architecture:
• Network layer (listeners/clients)
• Transport layer (TCP/TLS handshake)
• Protocol layer (SMTP command parser)
• Application logic layer (submission, auth, data)
• Separation of concerns: each SMTP verb/feature lives in its own file.
• Dependency inversion: submission modules depend on abstracted network interfaces.
Detail
• SMTP verb/feature as its own sub-component.
• Call out configuration injection into both listener and handler.