Help us shape the future of Go! Take the 2026 Go Developer Survey

smtpx

package
v1.27.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

based on https://github.com/DusanKasan/parsemail

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrQuit = errors.New("connection closed")
)

Functions

func SessionHandler

func SessionHandler(
	msgs Msg,
	log *slog.Logger,
	tlsConfig *tls.Config,
	onClose OnCloseFunc,
) netx.Handler

SessionHandler handles an SMTP session; it must be wrapped with netx.LoggingHandler.

func StripHTML

func StripHTML(htmlStr string) string

Types

type Address

type Address struct {
	Name    string `json:"name"`
	Address string `json:"address"`
}

type Data

type Data struct {
	// Helo is a "HELO" command data.
	Helo string `json:"helo"`

	// Ehlo is a "EHLO" command data.
	Ehlo string `json:"ehlo"`

	// MailFrom is a "MAIL FROM" command data.
	MailFrom string `json:"mailFrom"`

	// RcptTo is a "RCPT TO" command data.
	RcptTo []string `json:"rcptTo"`

	// Data is a "DATA" command data.
	Data string `json:"data"`
}

Data stores args passed to the corresponding SMTP commands.

type Email

type Email struct {
	Subject string     `json:"subject"`
	From    []Address  `json:"from"`
	To      []Address  `json:"to"`
	Cc      []Address  `json:"cc"`
	Bcc     []Address  `json:"bcc"`
	Date    *time.Time `json:"date"`
	Text    string     `json:"text"`
	HTML    string     `json:"html"`
}

func Parse

func Parse(data string) Email

Parse an email message read from io.Reader into parsemail.Email struct, only extracting text/plain.

type Meta

type Meta struct {
	Session Data  `json:"session"`
	Email   Email `json:"email"`
}

Meta contains SMTP-specific event metadata.

type Msg

type Msg struct {
	// Greet is server greet message.
	Greet string

	// Ehlo is a first line of EHLO command response.
	Ehlo string
}

Msg is used to store provided command responses.

type OnCloseFunc

type OnCloseFunc func(
	ctx context.Context,
	remoteAddr net.Addr,
	receivedAt *time.Time,
	secure bool,
	data [][]byte,
	match []byte,
	meta *Meta,
)

type Option

type Option func(*options)

func WithNotifyStarted added in v1.26.0

func WithNotifyStarted(f func()) Option

WithNotifyStarted sets a function called once the server is listening.

func WithTLSConfig added in v1.26.0

func WithTLSConfig(c *tls.Config) Option

WithTLSConfig makes the server accept TLS connections.

type Server

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

func New

func New(addr string, handler netx.Handler, opts ...Option) *Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

type StringBuilder

type StringBuilder interface {
	WriteString(s string) (int, error)
	WriteRune(r rune) (int, error)
	String() string
}

type WhitespaceCollapsingBuilder

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

func (*WhitespaceCollapsingBuilder) String

func (w *WhitespaceCollapsingBuilder) String() string

func (*WhitespaceCollapsingBuilder) WriteRune

func (w *WhitespaceCollapsingBuilder) WriteRune(r rune) (int, error)

func (*WhitespaceCollapsingBuilder) WriteString

func (w *WhitespaceCollapsingBuilder) WriteString(s string) (int, error)

Jump to

Keyboard shortcuts

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