smtpx

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 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

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,
	read []byte,
	written []byte,
	combined []byte,
	meta *Meta,
)

type Option

type Option func(*options)

func ListenerWrapper

func ListenerWrapper(f func(net.Listener) net.Listener) Option

func NotifyStartedFunc

func NotifyStartedFunc(f func()) Option

func TLSConfig

func TLSConfig(c *tls.Config) Option

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