Documentation
¶
Overview ¶
Package smtpd provides an SMTP server for receiving e-mails.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Connection ¶
Connection is implemented by the SMTP library and provided to callers customizing their own Servers.
type Envelope ¶
type Envelope struct {
Client Client
Sender MailAddress
Recipients []MailAddress
Data []byte
}
func (*Envelope) AddReceivedHeader ¶
func (*Envelope) AddRecipient ¶
func (e *Envelope) AddRecipient(rcpt MailAddress)
type MailAddress ¶
type MailAddress string
func (MailAddress) Email ¶
func (a MailAddress) Email() string
func (MailAddress) Hostname ¶
func (a MailAddress) Hostname() string
type SMTPError ¶
type SMTPError string
SMTPReply is a string to be sent to a client as an SMTP reply. E.g. "550 5.7.1 IP address blacklisted". SMTPReply is meant to be used as a return value in the callback functions in Server (e.g. OnMailFrom) that return an error. Bad things will happen if an SMTPError is not an SMTP error reply.
type Server ¶
type Server struct {
Addr string // TCP address to listen on, ":25" if empty
Hostname string // optional Hostname to announce; "" to use system hostname
ReadTimeout time.Duration // optional read timeout
WriteTimeout time.Duration // optional write timeout
// PregreetDelay is the amount of time to wait after sending the initial
// "220-" line before sending the final "220 " line.
PregreetDelay time.Duration
// OnNewConnection, if non-nil, is called on new connections.
// If it returns non-nil, the connection is closed.
OnNewConnection func(c Connection) error
// OnMailFrom, if non-nil, is called on MAIL FROM.
// If the callback returns an SMTPError, the MAIL FROM address is not added
// to the envelope, and the SMTPError is sent to the client as reply to
// MAIL FROM.
// If the callback returns a non-nil value that is not an SMTPError,
// the address is also not added to the envelope, and the server replies
// with "550 5.0.0 unacceptable sender" (permanent error).
OnMailFrom func(c Connection, from MailAddress) error
// OnRcptTo, if non-nil, is called on RCPT TO.
// If it returns non-nil, the recipient is not rejected and not added
// to the Envelope.
// If the callback returns an SMTPError, the RCPT TO address is not added
// to the envelope, and the SMTPError is sent to the client as reply to
// MAIL FROM.
// If the callback returns a non-nil value that is not an SMTPError,
// the address is also not added to the envelope, and the server replies
// with "550 5.0.0 unacceptable sender" (permanent error).
OnRcptTo func(c Connection, rcpt MailAddress) error
// Deliver is called when DATA is finished and the mail is ready to be
// accepted. If it returns non-nil, the mail is rejected.
Deliver func(env *Envelope) error
// Log is used for logging within the Server.
// If nil, logging is disabled.
Log *log.Logger
}
Server is an SMTP server.
func (*Server) Listen ¶
Listen listens on the TCP network address srv.Addr, but does not call Serve.
func (*Server) ListenAndServe ¶
ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. If srv.Addr is blank, ":25" is used.
func (*Server) Logf ¶
Logf calls Printf on srv.Log with the provided arguments if srv.Log is not nil.