Documentation
¶
Overview ¶
smtp package implements a rather forgiving TCP server that carries on and decodes an SMTP conversation. I would like to express my gratitude to Chris Siebenmann for his inspiring pioneer work on an implementation of SMTP server written in go.
Index ¶
Constants ¶
const ( StageGreeting commandStage = iota StageAfterGreeting commandStage = 1 << iota StageHello StateMailAddress StageRecipient StageMessageData StageAfterMessageData StageQuit StageAbort )
const MaxCommandLength = 4096
MaxCommandLength is the maximum acceptable length of a command in the middle of an ongoing SMTP conversation. The maximum length does not apply to mail message and attachments.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct { State ConversationState Verb ProtocolVerb Parameter string }
Command comes from the result of interpretation of latest protocol command in an ongoing conversation. In addition to stating whether the SMTP conversation is carrying on, it also records the latest protocol command verb and parameter value.
type Config ¶
type Config struct { // TLSConfig grants SMTP server StartTLS capability. TLSConfig *tls.Config // IOTimeout governs the timeout of each read and write operation. IOTimeout time.Duration /* MaxMessageLength is the maximum size (in bytes) of a mail message (and attachment) during an SMTP conversation. An ordinary protocol command that does not carry mail message nor attachment uses MaxCommandLength constant instead. */ MaxMessageLength int64 /* MaxConsecutiveUnrecognisedCommands is the maximum number of unknown protocol commands to tolerate before giving up on the connection, which will result in the connection being closed. */ MaxConsecutiveUnrecognisedCommands int /* ServerName is the complete Internet host name of the mail server, it is used to greet mail clients. Some clients use the greeting to further establish authenticity of the mail server. */ ServerName string }
Config provides behaviour and fault tolerance tuning to SMTP conversation connection.
type Connection ¶
type Connection struct { // Config is supplied by caller. Config Config // TLSAttempted is an indication flag to inform caller that StartTLS has been attempted. TLSAttempted bool // TLSState helps caller to debug TLS connection issue. TLSState tls.ConnectionState // TLSHelp contains a text description that explains the latest TLS error from SMTP conversation's perspective. TLSHelp string // contains filtered or unexported fields }
Connection is the server side of an SMTP connection and it offers functions for caller to interact with an SMTP conversation, and eventually acquire the complete mail message prior to the conclusion of the connection.
func NewConnection ¶
func (*Connection) AnswerNegative ¶
func (conn *Connection) AnswerNegative()
AnswerNegative produces a negative reply appropriate for the stage of SMTP conversation.
func (*Connection) AnswerRateLimited ¶
func (conn *Connection) AnswerRateLimited()
AnswerRateLimited produces a negative answer to the SMTP conversation to inform SMTP client that it has been rate limited. The connection is closed afterwards.
func (*Connection) CarryOn ¶
func (conn *Connection) CarryOn() Command
CarryOn continues the SMTP conversation until the next stage is reached, at which point the latest command (such as mail address or mail data) is returned to caller.
type ConversationState ¶
type ConversationState int
ConversationState represents the latest state of the ongoing SMTP conversation, determined by the latest series of protocol commands. Caller may use the state to determine whether the conversation is carrying on, and whether mail message has been received completely.
const ( ConvReceivedCommand ConversationState = iota ConvReceivedData ConvCompleted ConvAborted )
type ProtocolVerb ¶
type ProtocolVerb int
ProtocolVerb is an enumeration of SMTP verbs supported by this server.
const ( VerbAbsent ProtocolVerb = iota VerbUnknown ProtocolVerb = iota VerbHELO VerbEHLO VerbSTARTTLS VerbVRFY VerbMAILFROM VerbRCPTTO VerbDATA VerbQUIT VerbRSET VerbNOOP )
func (ProtocolVerb) String ¶
func (verb ProtocolVerb) String() string
String returns a descriptive string representation of an SMTP Verb.