smtpServerProtocol

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2023 License: MIT-0 Imports: 9 Imported by: 0

README

SMTP server protocol

RFC spec you can read here

Authentication

Some informative doc can be found here

Documentation

Index

Constants

View Source
const (
	CommandHelo = CommandName("HELO")
	CommandEhlo = CommandName("EHLO")
	CommandAuth = CommandName("AUTH")
	CommandMail = CommandName("MAIL")
	CommandRset = CommandName("RSET")
	CommandRcpt = CommandName("RCPT")
	CommandData = CommandName("DATA")
	CommandQuit = CommandName("QUIT")
)

RSET

View Source
const (
	StateCommandsExchange = ConversationState("commands_exchange")
	StateWaitingAuth      = ConversationState("waiting_auth")
	StateData             = ConversationState("data")
	StateCustomScene      = ConversationState("custom_scene")
)
View Source
const (
	CODE_SYSTEM_STATUS             = 211
	CODE_HELP_MESSAGE              = 214
	CODE_SERVICE_READY             = 220
	CODE_SERVICE_CLOSING           = 221
	CODE_AUTHENTICATION_SUCCESS    = 235
	CODE_ACTION_OK                 = 250
	CODE_USER_IS_NOT_LOCAL         = 251 // will forward to <forward-path>
	CODE_USER_NOT_VERIFIED         = 252
	CODE_AUTH_CREDENTIALS          = 334
	CODE_MAIL_DATA                 = 354
	CODE_SERVICE_NOT_AVAILABLE     = 421
	CODE_MAILBOX_UNAVAILABLE       = 450
	CODE_LOCAL_ERROR               = 451
	CODE_EXCEEDED_SYSTEM_STORAGE   = 452
	CODE_COMMAND_SYNTAX_ERROR      = 500
	CODE_PARAMETER_SYNTAX_ERROR    = 501
	CODE_COMMAND_NOT_IMPLEMENTED   = 502
	CODE_COMMANDS_BAD_SEQUENCE     = 503
	CODE_PARAMETER_NOT_IMPLEMENTED = 504
	CODE_AUTH_FAILED               = 535
	CODE_MAILBOX_404               = 550
	CODE_USER_NOT_LOCAL            = 551 // please try <forward-path>
	CODE_EXCEEDED_STORAGE          = 552
	CODE__MAILBOX_NAME_INCORRECT   = 553
	CODE_TRANSACTION_FAILED        = 554
)
View Source
const CommandEndSymbol = "\r\n"

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command is a struct representing an SMTP command (verb + arguments)

func CommandFromLine

func CommandFromLine(line string) *Command

type CommandName

type CommandName string

type ConversationState

type ConversationState string

type Protocol

type Protocol struct {
	Hostname string
	Ip       *net.TCPAddr
	// contains filtered or unexported fields
}

func CreateProtocol

func CreateProtocol(hostname string, ip *net.TCPAddr, validation *Validation) *Protocol

func (*Protocol) CreateCustomSceneUsing

func (protocol *Protocol) CreateCustomSceneUsing(callback func(sceneName string) Scene)

func (*Protocol) EHLO

func (protocol *Protocol) EHLO(command *Command) *Reply

func (*Protocol) HELO

func (protocol *Protocol) HELO(command *Command) *Reply

func (*Protocol) HandleReceivedLine

func (protocol *Protocol) HandleReceivedLine(receivedLine string) *Reply

func (*Protocol) MAIL

func (protocol *Protocol) MAIL(command *Command) *Reply

func (*Protocol) OnMessageReceived

func (protocol *Protocol) OnMessageReceived(callback func(message *smtpMessage.SMTPMessage) (string, error))

func (*Protocol) ParseFROM

func (protocol *Protocol) ParseFROM(mail string) (string, error)

func (*Protocol) ParseRCPT

func (protocol *Protocol) ParseRCPT(mail string) (string, error)

func (*Protocol) RCPT

func (protocol *Protocol) RCPT(command *Command) *Reply

func (*Protocol) RSET

func (protocol *Protocol) RSET(command *Command) *Reply

func (*Protocol) SayWelcome

func (protocol *Protocol) SayWelcome(identification string) *Reply

func (*Protocol) SetAuthMechanisms

func (protocol *Protocol) SetAuthMechanisms(authMechanisms []string)

func (*Protocol) SetStateCommandsExchange

func (protocol *Protocol) SetStateCommandsExchange()

type Reply

type Reply struct {
	Status int
	// contains filtered or unexported fields
}

Reply is a struct representing an SMTP reply (status code + lines)

func ReplyAuthCredentials

func ReplyAuthCredentials(response string) *Reply

ReplyAuthCredentials creates reply with a 334 code and requests a username

func ReplyAuthFailed

func ReplyAuthFailed(response string) *Reply

ReplyAuthFailed creates reply with auth failed response

func ReplyAuthOk

func ReplyAuthOk() *Reply

ReplyAuthOk creates a authentication successful reply

func ReplyBye

func ReplyBye() *Reply

func ReplyCommandNotImplemented

func ReplyCommandNotImplemented() *Reply

func ReplyExceededStorage

func ReplyExceededStorage(response string) *Reply

func ReplyLineTooLong

func ReplyLineTooLong() *Reply

ReplyLineTooLong due to exceeding these limits

func ReplyMailData

func ReplyMailData() *Reply

func ReplyMailbox404

func ReplyMailbox404(response string) *Reply

func ReplyOk

func ReplyOk(message ...string) *Reply

func ReplyServiceReady

func ReplyServiceReady(identification string) *Reply

ReplyServiceReady creates a welcome reply

func ReplyUnrecognisedCommand

func ReplyUnrecognisedCommand() *Reply

func (Reply) Lines

func (r Reply) Lines() []string

Lines returns the formatted SMTP reply

type Scene

type Scene interface {
	// Start scene by send specific message (reply) to client.
	Start(receivedLine string, protocol *Protocol) *Reply
	// ReadAndWriteReply reads client message and write reply
	ReadAndWriteReply(receivedLine string) *Reply
	// Finish scene, by notifying protocol to finish this scene
	Finish()
}

Scene represents custom logic flow (scene) for some specific set of commands, for example authentication.

type Validation

type Validation struct {
	MaximumLineLength int
	MaximumReceivers  int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL