smtp

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(rt *runner.Runtime, sender Sender)

Register binds mail() to sender. The standard library itself is registered separately by the embedding host (stdlib.Register).

func RegisterSMTP added in v0.2.4

func RegisterSMTP(rt *runner.Runtime)

RegisterSMTP installs the SMTP class binding, so `new SMTP` in a script constructs a script-configured sender.

func SenderContext added in v0.2.4

func SenderContext(ctx context.Context, sender Sender) context.Context

SenderContext binds a Sender into the context. A runtime running with that context constructs `new SMTP` clients that hand their messages to the sender rather than dialing the configured host, which is how a host captures mail (see Memory) without a mail server.

Types

type Config

type Config struct {
	Host     string `yaml:"host" json:"host"`
	Port     int    `yaml:"port" json:"port"`
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
	From     string `yaml:"from" json:"from"`

	// Insecure accepts the STARTTLS certificate without verifying its chain or
	// names. Hosts that present a self-signed certificate, or one carrying no
	// subjectAltName, are unreachable without it.
	Insecure bool `yaml:"insecure" json:"insecure"`
}

Config contains the connection and sender settings for SMTP.

type Memory added in v0.2.4

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

Memory is a Sender that appends messages to an in-memory queue instead of delivering them. Hosts bind one with SenderContext to capture what scripts send (tests, local runs, dry runs).

func NewMemory added in v0.2.4

func NewMemory() *Memory

NewMemory creates an empty in-memory sender.

func (*Memory) Messages added in v0.2.4

func (m *Memory) Messages() []Message

Messages returns the queued messages in send order.

func (*Memory) Next added in v0.2.4

func (m *Memory) Next() (Message, bool)

Next pops the oldest queued message, reporting whether one was queued.

func (*Memory) Reset added in v0.2.4

func (m *Memory) Reset()

Reset empties the queue.

func (*Memory) Send added in v0.2.4

func (m *Memory) Send(recipient, subject, body string) error

Send queues a message.

type Message added in v0.2.4

type Message struct {
	Recipient string
	Subject   string
	Body      string
}

Message is a queued email.

type SMTP

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

SMTP implements the Sender interface using SMTP

func NewSMTP

func NewSMTP(config Config) *SMTP

NewSMTP creates a new SMTP client

func NewSMTPBinding added in v0.2.4

func NewSMTPBinding(ctx context.Context, options any) (*SMTP, error)

NewSMTPBinding is a mail sender configured for one SMTP server. It takes the connection settings as an associative array:

$smtp = new SMTP(array(
	"host"     => "mail.example.com",
	"port"     => 587,
	"username" => "noreply@example.com",
	"password" => "secret",
	"from"     => "Example <noreply@example.com>",
	"insecure" => true,
));

func (*SMTP) Send

func (s *SMTP) Send(ctx context.Context, recipient, subject, body string) (err error)

Send sends an email via SMTP. It takes a context so the delivery is recorded on the trace of the request that asked for it; the runtime injects it, so a script still calls `$smtp->send($to, $subject, $body)`.

type Sender

type Sender interface {
	Send(recipient, subject, body string) error
}

Sender interface defines methods for sending emails

Jump to

Keyboard shortcuts

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