Documentation ¶
Overview ¶
Package smtpd implements an SMTP server with support for STARTTLS, authentication (PLAIN/LOGIN), XCLIENT and optional restrictions on the different stages of the SMTP session.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Envelope ¶
Envelope holds a message
func (*Envelope) AddReceivedLine ¶
AddReceivedLine prepends a Received header to the Data
type Peer ¶
type Peer struct { HeloName string // Server name used in HELO/EHLO command Username string // Username from authentication, if authenticated Password string // Password from authentication, if authenticated Protocol Protocol // Protocol used, SMTP or ESMTP ServerName string // A copy of Server.Hostname Addr net.Addr // Network address TLS *tls.ConnectionState // TLS Connection details, if on TLS }
Peer represents the client connecting to the server
type Protocol ¶
type Protocol string
Protocol represents the protocol used in the SMTP session
const ( // SMTP SMTP Protocol = "SMTP" // Extended SMTP ESMTP = "ESMTP" )
type Server ¶
type Server struct { Hostname string // Server hostname. (default: "localhost.localdomain") WelcomeMessage string // Initial server banner. (default: "<hostname> ESMTP ready.") ReadTimeout time.Duration // Socket timeout for read operations. (default: 60s) WriteTimeout time.Duration // Socket timeout for write operations. (default: 60s) DataTimeout time.Duration // Socket timeout for DATA command (default: 5m) MaxConnections int // Max concurrent connections, use -1 to disable. (default: 100) MaxMessageSize int // Max message size in bytes. (default: 10240000) MaxRecipients int // Max RCPT TO calls for each envelope. (default: 100) // New e-mails are handed off to this function. // Can be left empty for a NOOP server. // If an error is returned, it will be reported in the SMTP session. Handler func(peer Peer, env Envelope) error DataWriter func(peer Peer) ([]byte, io.WriteCloser, error) // Enable various checks during the SMTP session. // Can be left empty for no restrictions. // If an error is returned, it will be reported in the SMTP session. // Use the Error struct for access to error codes. ConnectionChecker func(peer Peer) error // Called upon new connection. HeloChecker func(peer Peer, name string) error // Called after HELO/EHLO. SenderChecker func(peer Peer, addr string) error // Called after MAIL FROM. RecipientChecker func(peer Peer, addr string) error // Called after each RCPT TO. // Enable PLAIN/LOGIN authentication, only available after STARTTLS. // Can be left empty for no authentication support. Authenticator func(peer Peer, username, password string) error EnableXCLIENT bool // Enable XCLIENT support (default: false) EnableProxyProtocol bool // Enable proxy protocol support (default: false) TLSConfig *tls.Config // Enable STARTTLS support. ForceTLS bool // Force STARTTLS usage. ProtocolLogger *log.Logger }
Server defines the parameters for running the SMTP server
Example ¶
package main import ( "errors" "net/smtp" "strings" "github.com/Supme/smtpd" ) func main() { var server *smtpd.Server // No-op server. Accepts and discards server = &smtpd.Server{} server.ListenAndServe("127.0.0.1:10025") // Relay server. Accepts only from single IP address and forwards using the Gmail smtp server = &smtpd.Server{ HeloChecker: func(peer smtpd.Peer, name string) error { if !strings.HasPrefix(peer.Addr.String(), "42.42.42.42:") { return errors.New("Denied") } return nil }, Handler: func(peer smtpd.Peer, env smtpd.Envelope) error { return smtp.SendMail( "smtp.gmail.com:587", smtp.PlainAuth( "", "username@gmail.com", "password", "smtp.gmail.com", ), env.Sender, env.Recipients, env.Data, ) }, } server.ListenAndServe("127.0.0.1:10025") }
Output:
func (*Server) ListenAndServe ¶
ListenAndServe starts the SMTP server and listens on the address provided
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
dkim-proxy
Command dkim-proxy implements a simple SMTP proxy that DKIM signs incoming e-mail and relays to another SMTP server for delivery
|
Command dkim-proxy implements a simple SMTP proxy that DKIM signs incoming e-mail and relays to another SMTP server for delivery |
Click to show internal directories.
Click to hide internal directories.