Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Attachment ¶
Attachment represents an email attachment.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client sends outbound emails.
func NewClient ¶
func NewClient(cfg ClientConfig) *Client
NewClient creates an outbound SMTP client.
func (*Client) Send ¶
func (c *Client) Send(email *OutboundEmail) error
Send delivers an outbound email. If a relay host is configured, delivery goes through the authenticated smarthost. Otherwise, direct MX is used.
func (*Client) SetDialer ¶
func (c *Client) SetDialer(d SMTPDialer)
SetDialer replaces the SMTP dialer (for testing).
func (*Client) SetResolver ¶
func (c *Client) SetResolver(r MXResolver)
SetResolver replaces the MX resolver (for testing).
type ClientConfig ¶
type ClientConfig struct {
// FromDomain is the bridge's email domain for the From address.
FromDomain string
// DKIMSigner signs outbound messages. Nil disables DKIM.
DKIMSigner *DKIMSigner
// RelayHost is the SMTP smarthost for outbound delivery.
// If empty, direct MX delivery is used.
RelayHost string
// RelayPort is the smarthost port (typically 587 for STARTTLS).
RelayPort int
// RelayUsername is the SMTP AUTH username.
RelayUsername string
// RelayPassword is the SMTP AUTH password.
RelayPassword string
// MXPort overrides the port used for direct MX delivery.
// If zero (default), tries 2525 then falls back to 25.
MXPort int
}
ClientConfig holds outbound SMTP client configuration.
type DKIMSigner ¶
type DKIMSigner struct {
// contains filtered or unexported fields
}
DKIMSigner signs outbound emails with a DKIM signature.
func NewDKIMSigner ¶
func NewDKIMSigner(domain, selector, keyPath string) (*DKIMSigner, error)
NewDKIMSigner creates a DKIM signer from a PEM-encoded RSA private key file.
func NewDKIMSignerFromKey ¶
func NewDKIMSignerFromKey(domain, selector string, key crypto.Signer) *DKIMSigner
NewDKIMSignerFromKey creates a DKIM signer from an in-memory key. Useful for testing.
func NewDKIMSignerFromPEM ¶
func NewDKIMSignerFromPEM(domain, selector string, pemData []byte) (*DKIMSigner, error)
NewDKIMSignerFromPEM creates a DKIM signer from PEM-encoded key bytes.
func (*DKIMSigner) Sign ¶
func (ds *DKIMSigner) Sign(msg []byte) ([]byte, error)
Sign adds a DKIM-Signature header to the message. Returns the signed message bytes.
type InboundEmail ¶
InboundEmail represents a parsed inbound email ready for bridge processing.
type InboundHandler ¶
type InboundHandler func(email *InboundEmail) error
InboundHandler is called when a valid inbound email is received.
type MXResolver ¶
MXResolver looks up MX records for a domain. The default is net.LookupMX.
type OutboundEmail ¶
type OutboundEmail struct {
From string // e.g., "npub1abc@relay.example.com"
To []string // recipient email addresses
Cc []string
Bcc []string
Subject string
Body string
}
OutboundEmail represents an email to be sent.
type ParsedMIME ¶
type ParsedMIME struct {
From string
To []string
Cc []string
Subject string
MessageID string
InReplyTo string
TextPlain string
TextHTML string
Attachments []Attachment
}
ParsedMIME represents a parsed email message.
func ParseMIME ¶
func ParseMIME(raw []byte) (*ParsedMIME, error)
ParseMIME parses a raw email message into structured fields.
type SMTPDialer ¶
SMTPDialer connects to an SMTP server. The default is gosmtp.Dial.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps go-smtp to receive inbound emails for the bridge.
func NewServer ¶
func NewServer(cfg ServerConfig, handler InboundHandler) *Server
NewServer creates an SMTP server with the given configuration. The handler is called for each valid inbound email.
func (*Server) Addr ¶
Addr returns the listener's address, useful for tests.
type ServerConfig ¶
type ServerConfig struct {
// Domain is the bridge's email domain (e.g., "relay.example.com").
Domain string
// ListenAddr is the address to listen on (e.g., "0.0.0.0:2525").
ListenAddr string
// MaxMessageBytes is the maximum message size (default: 25MB).
MaxMessageBytes int64
// MaxRecipients is the maximum recipients per message (default: 10).
MaxRecipients int
// ReadTimeout is the per-command read timeout (default: 60s).
ReadTimeout time.Duration
// WriteTimeout is the per-command write timeout (default: 60s).
WriteTimeout time.Duration
}
ServerConfig holds SMTP server configuration.
func DefaultServerConfig ¶
func DefaultServerConfig(domain string) ServerConfig
DefaultServerConfig returns sensible defaults for the SMTP server.
Source Files
¶
- client.go
- dkim.go
- mime.go
- server.go
- session.go