Documentation ¶
Overview ¶
Package smtpd is a SMTP server.
Index ¶
Examples ¶
Constants ¶
View Source
const ( StatusPasswordNeeded = 432 StatusMessageError = 450 StatusMessageExceedStorage = 452 StatusTempAuthFailure = 454 StatusAuthInvalid = 535 StatusAuthRequired = 530 StatusEncryptionRequired = 538 StatusServerError = 550 StatusExceedStorage = 552 )
Variables ¶
View Source
var ( ErrPasswordNeeded = Error{Code: StatusPasswordNeeded, Message: StatusString(StatusPasswordNeeded)} ErrMessageError = Error{Code: StatusMessageError, Message: StatusString(StatusMessageError)} ErrMessageExceedStorage = Error{Code: StatusMessageExceedStorage, Message: StatusString(StatusMessageExceedStorage)} ErrTempAuthFailure = Error{Code: StatusTempAuthFailure, Message: StatusString(StatusTempAuthFailure)} ErrAuthInvalid = Error{Code: StatusAuthInvalid, Message: StatusString(StatusAuthInvalid)} ErrAuthRequired = Error{Code: StatusAuthRequired, Message: StatusString(StatusAuthRequired)} ErrServerError = Error{Code: StatusServerError, Message: StatusString(StatusServerError)} ErrExceedStorage = Error{Code: StatusExceedStorage, Message: StatusString(StatusExceedStorage)} )
Functions ¶
func StatusString ¶
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 Protocol = "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 // 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) TLSConfig *tls.Config // Enable STARTTLS support. ForceTLS bool // Force STARTTLS usage. }
Server defines the parameters for running the SMTP server
Example ¶
package main import ( "errors" "net/smtp" "strings" "bitbucket.org/kardianos/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.