smtp

package
v1.33.3 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	StartTLSOff      = "off"
	StartTLSAuto     = "auto"
	StartTLSRequired = "required"
)

The values of starttls.

Variables

This section is empty.

Functions

func Deliver added in v1.30.0

func Deliver(data map[string]any, opts ...Option) (map[string]any, error)

Deliver runs the smtp action: it reads the parameters in data, sends the mail they describe, and returns the result as a map.

func Spec added in v1.30.0

func Spec() actionspec.Spec

Spec declares the smtp action. It keeps to no guard, as it does not check what it is about to do against one, so that a guard refuses it unless it is allowed by name. It cannot run without addr, from and to.

Types

type Action

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

func (*Action) Run

func (a *Action) Run(with map[string]any) (map[string]any, error)

type Bulk

type Bulk struct {
	Addr       string
	From       string
	To         string
	Subject    string
	MyHostname string
	Session    int
	Message    int
	Length     int

	// StartTLS is off, auto or required, as the smtp action's starttls. It
	// is off when empty, as Bulk always was.
	StartTLS string
	// InsecureSkipTLS accepts any certificate after STARTTLS.
	InsecureSkipTLS bool
	// Timeout is each session's Mail.Timeout. Zero means no limit.
	Timeout time.Duration
	// contains filtered or unexported fields
}

Bulk sends Message generated messages from From to To over Session SMTP sessions at the same time. Req.Do builds it from the smtp action's parameters once they are checked.

func (*Bulk) DeliverWithResult

func (b *Bulk) DeliverWithResult() DeliveryResult

type Callback

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

type Client

type Client struct {
	Text *textproto.Conn
	// contains filtered or unexported fields
}

Client is an SMTP client forked from net/smtp, keeping what the smtp action uses of it.

func Dial

func Dial(addr string, timeout time.Duration) (*Client, error)

Dial connects to the SMTP server at addr and reads its greeting. A timeout above zero limits connecting, and each read from and write to the connection after, so that a server that stops answering fails the session rather than holding it. The reply to the end of a message may take twice the timeout, as RFC 5321 4.5.3.2 gives it 10 minutes against 5 for the other replies: a server may check the message before it answers. Zero means no limit.

func NewClient

func NewClient(conn net.Conn, host string) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Data

func (c *Client) Data() (io.WriteCloser, error)

func (*Client) Extension

func (c *Client) Extension(ext string) (bool, string)

func (*Client) Hello

func (c *Client) Hello(localName string) error

func (*Client) Mail

func (c *Client) Mail(from string) error

func (*Client) Quit

func (c *Client) Quit() error

func (*Client) Rcpt

func (c *Client) Rcpt(to string) error

func (*Client) StartTLS

func (c *Client) StartTLS(config *tls.Config) error

type DeliveryResult

type DeliveryResult struct {
	Sent     int
	Failed   int
	Total    int
	Sessions int
	Error    string
	// Rejected is set when a failed session got a reply from the server,
	// such as a 550 to RCPT TO, rather than failing to reach it.
	Rejected bool
	// LastSent is the last message a server accepted, as it was sent, or
	// nil when none was. The sessions run at the same time, so it is the
	// last message of whichever session finished last, which need not be
	// the message accepted last.
	LastSent *SentMessage
}

type Mail

type Mail struct {
	Addr string
	// LocalName is the host name sent in EHLO and HELO. When it is empty the
	// machine's host name is used, falling back to "localhost".
	LocalName        string
	MailFrom         string
	RcptTo           []string
	Data             []byte
	StartTLSDisabled bool
	// StartTLSRequired fails the session when the server does not offer
	// STARTTLS, instead of going on in plain text.
	StartTLSRequired bool
	// InsecureSkipVerify accepts any certificate after STARTTLS, such as a
	// self-signed one.
	InsecureSkipVerify bool
	// Timeout limits connecting, and each wait on the server to read or
	// write, as Dial takes it. Zero means no limit.
	Timeout      time.Duration
	MessageCount int
	// Delivered is how many messages the server accepted in the last
	// SendSession. Each message is committed on its own, so a session that
	// fails part way has still delivered the ones before.
	Delivered int
	// LastSent is the last message the server accepted in the last
	// SendSession, as it was written to DATA, with its Message-ID and send
	// time. It is nil when none was accepted.
	LastSent *SentMessage
}

func (*Mail) SendSession added in v1.30.0

func (m *Mail) SendSession() error

SendSession opens one SMTP session to Addr and sends MessageCount copies of Data in it, each stamped with its own Message-ID and send time.

type Option

type Option func(*Callback)

func WithAfter

func WithAfter(f func(result *Result)) Option

func WithBefore

func WithBefore(f func(from string, to string, subject string)) Option

type Req

type Req struct {
	Addr       string `map:"addr" validate:"required"`
	From       string `map:"from" validate:"required"`
	To         string `map:"to" validate:"required"`
	Subject    string `map:"subject"`
	MyHostname string `map:"myhostname"`
	Session    int    `map:"session"`
	Message    int    `map:"message"`
	Length     int    `map:"length"`
	// StartTLS is off, auto (use it when the server offers it) or required
	// (fail when it does not).
	StartTLS        string `map:"starttls"`
	InsecureSkipTLS bool   `map:"insecure_skip_tls"`
	// Timeout limits connecting to the server, and each wait on it to
	// read or write in a session, with twice it for the reply to the end of
	// a message. Zero, possible only through the Go API, means no limit.
	Timeout time.Duration `map:"timeout"`
	// contains filtered or unexported fields
}

func NewReq

func NewReq() *Req

func (*Req) Do

func (r *Req) Do() (*Result, error)

type Res

type Res struct {
	Code   int    `map:"code"`
	Sent   int    `map:"sent"`
	Failed int    `map:"failed"`
	Total  int    `map:"total"`
	Error  string `map:"error"`
	// MailData is the last message the server accepted, as it was sent.
	MailData string `map:"maildata"`
}

type Result

type Result struct {
	Req    Req           `map:"req"`
	Res    Res           `map:"res"`
	RT     time.Duration `map:"rt"`
	Status int           `map:"status"`
}

type SentMessage added in v1.30.0

type SentMessage struct {
	Header []byte
	Body   []byte
}

SentMessage is a message as it was written to DATA: its own headers, and the body it shares, unchanged, with the other messages of the session.

func (*SentMessage) String added in v1.30.0

func (m *SentMessage) String() string

String returns the message as one text, or "" for a nil message.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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