Documentation
¶
Index ¶
- Constants
- func Deliver(data map[string]any, opts ...Option) (map[string]any, error)
- func Spec() actionspec.Spec
- type Action
- type Bulk
- type Callback
- type Client
- func (c *Client) Close() error
- func (c *Client) Data() (io.WriteCloser, error)
- func (c *Client) Extension(ext string) (bool, string)
- func (c *Client) Hello(localName string) error
- func (c *Client) Mail(from string) error
- func (c *Client) Quit() error
- func (c *Client) Rcpt(to string) error
- func (c *Client) StartTLS(config *tls.Config) error
- type DeliveryResult
- type Mail
- type Option
- type Req
- type Res
- type Result
- type SentMessage
Constants ¶
const ( StartTLSOff = "off" StartTLSAuto = "auto" StartTLSRequired = "required" )
The values of starttls.
Variables ¶
This section is empty.
Functions ¶
func Deliver ¶
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 ¶
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 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 Client ¶
Client is an SMTP client forked from net/smtp, keeping what the smtp action uses of it.
func Dial ¶
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.
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 ¶
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 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
}
type SentMessage ¶
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 ¶
func (m *SentMessage) String() string
String returns the message as one text, or "" for a nil message.