SMTP Server
(require net/smtp-server) | package: smtp-server |
This module module provides a minimal implementation of RFC 5321 [RFC5321] that can receive e-mail messages.
1 Usage
(define stop (start-smtp-server println))
The example above starts an SMTP server on localhost port 25 that prints all incoming e-mail to standard out. Calling the stop function terminates any connections in flight and stops the server.
See "example/" in the source code repository for an example with STARTTLS support.
2 Reference
value
tls-encode-proc/c :
(-> input-port? output-port? #:mode 'tcp #:encrypt 'tls #:close-original? #t (values input-port? output-port?))
parameter
(current-smtp-hostname hostname) → void? hostname : non-empty-string?
= (gethostname)
struct
(struct envelope (sender recipients data) #:extra-constructor-name make-envelope) sender : bytes? recipients : (listof bytes?) data : bytes?
procedure
(start-smtp-server handler [ #:host host #:port port #:limits lim #:tls-encode tls-encode]) → (-> void?) handler : (-> envelope? void?) host : string? = "127.0.0.1" port : (integer-in 0 65535) = 25 lim : smtp-limits? = (make-smtp-limits) tls-encode : (or/c #f tls-encode-proc/c) = #f
Successfully-received e-mails are passed to handler. When the handler raises an exception, the server notifies the client that the message has been rejected.
The #:limits arguments can be used to customize various security limits.
If the optional #:tls-encode argument supplies a tls-encode-proc/c value, the server advertises STARTTLS support and clients may opt in to TLS encryption.
procedure
(smtp-limits? v) → boolean?
v : any/c
procedure
(make-smtp-limits [ #:max-connections max-connections #:max-line-length max-line-length #:max-envelope-length max-envelope-length #:session-timeout session-timeout]) → smtp-limits? max-connections : exact-positive-integer? = 512 max-line-length : exact-nonnegative-integer? = 1024
max-envelope-length : exact-nonnegative-integer? = (* 10 1024 1024) session-timeout : (and/c number? positive?) = 300
The #:max-connections argument controls the maximum number of concurrent client connections that the server will accept at a time.
The #:max-line-length argument controls the maximum length in bytes of each line received from a client may be. The server will reject lines longer than this amount.
The #:max-envelope-length argument controls the maximum length of incoming e-mails from clients. The total length of an envlope includes the length in bytes of the sender and the recipients list as well as the message data.
The #:session-timeout argument controls the maximum amount of time, in seconds, that a client session may be open for.
Bibliography
[RFC5321] | J. Klensin, “Simple Mail Transfer Protocol.” 2008. https://www.ietf.org/rfc/rfc5321.html |