Documentation
¶
Index ¶
- func SendMail(addr string, a sasl.Client, from string, to []string, r io.Reader) error
- func SendMailTLS(addr string, a sasl.Client, from string, to []string, r io.Reader) error
- type Client
- func Dial(addr string) (*Client, error)
- func DialStartTLS(addr string, tlsConfig *tls.Config) (*Client, error)
- func DialTLS(addr string, tlsConfig *tls.Config) (*Client, error)
- func NewClient(conn net.Conn) *Client
- func NewClientLMTP(conn net.Conn) *Client
- func NewClientStartTLS(conn net.Conn, tlsConfig *tls.Config) (*Client, error)
- func (c *Client) Auth(a sasl.Client) error
- func (c *Client) Close() error
- func (c *Client) Data() (*DataCloser, error)
- func (c *Client) Extension(ext string) (bool, string)
- func (c *Client) Hello(localName string) error
- func (c *Client) LMTPData(statusCb func(rcpt string, status *smtp.SMTPStatus)) (*DataCloser, error)
- func (c *Client) Mail(from string, opts *smtp.MailOptions) error
- func (c *Client) MaxMessageSize() (size int, ok bool)
- func (c *Client) Noop() error
- func (c *Client) Quit() error
- func (c *Client) Rcpt(to string, opts *smtp.RcptOptions) error
- func (c *Client) Reset() error
- func (c *Client) SendMail(from string, to []string, r io.Reader) error
- func (c *Client) SupportsAuth(mech string) bool
- func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool)
- func (c *Client) Verify(addr string) error
- type DataCloser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SendMail ¶
SendMail connects to the server at addr, switches to TLS, authenticates with the optional SASL client, and then sends an email from address from, to addresses to, with message r. The addr must include a port, as in "mail.example.com:smtp".
The addresses in the to parameter are the SMTP RCPT addresses.
The r parameter should be an RFC 822-style email with headers first, a blank line, and then the message body. The lines of r should be CRLF terminated. The r headers should usually include fields such as "From", "To", "Subject", and "Cc". Sending "Bcc" messages is accomplished by including an email address in the to parameter but not including it in the r headers.
SendMail is intended to be used for very simple use-cases. If you want to customize SendMail's behavior, use a Client instead.
The SendMail function and the go-smtp package are low-level mechanisms and provide no support for DKIM signing (see go-msgauth), MIME attachments (see the mime/multipart package or the go-message package), or other mail functionality.
Types ¶
type Client ¶
type Client struct { // Time to wait for command responses (this includes 3xx reply to DATA). CommandTimeout time.Duration // Time to wait for responses after final dot. SubmissionTimeout time.Duration // Logger for all network activity. Debug io.Writer // contains filtered or unexported fields }
A Client represents a client connection to an SMTP server.
func Dial ¶
Dial returns a new Client connected to an SMTP server at addr. The addr must include a port, as in "mail.example.com:smtp".
This function returns a plaintext connection. To enable TLS, use DialStartTLS.
func DialStartTLS ¶
DialStartTLS retruns a new Client connected to an SMTP server via STARTTLS at addr. The addr must include a port, as in "mail.example.com:smtp".
A nil tlsConfig is equivalent to a zero tls.Config.
func DialTLS ¶
DialTLS returns a new Client connected to an SMTP server via TLS at addr. The addr must include a port, as in "mail.example.com:smtps".
A nil tlsConfig is equivalent to a zero tls.Config.
func NewClient ¶
NewClient returns a new Client using an existing connection and host as a server name to be used when authenticating.
func NewClientLMTP ¶
NewClientLMTP returns a new LMTP Client (as defined in RFC 2033) using an existing connection and host as a server name to be used when authenticating.
func NewClientStartTLS ¶
NewClientStartTLS creates a new Client and performs a STARTTLS command.
func (*Client) Auth ¶
Auth authenticates a client using the provided authentication mechanism. Only servers that advertise the AUTH extension support this function.
If server returns an error, it will be of type *smtp.
func (*Client) Data ¶
func (c *Client) Data() (*DataCloser, error)
Data issues a DATA command to the server and returns a writer that can be used to write the mail headers and body. The caller should close the writer before calling any more methods on c. A call to Data must be preceded by one or more calls to Rcpt.
If server returns an error, it will be of type *smtp.
func (*Client) Extension ¶
Extension reports whether an extension is support by the server. The extension name is case-insensitive. If the extension is supported, Extension also returns a string that contains any parameters the server specifies for the extension.
func (*Client) Hello ¶
Hello sends a HELO or EHLO to the server as the given host name. Calling this method is only necessary if the client needs control over the host name used. The client will introduce itself as "localhost" automatically otherwise. If Hello is called, it must be called before any of the other methods.
If server returns an error, it will be of type *smtp.
func (*Client) LMTPData ¶
func (c *Client) LMTPData(statusCb func(rcpt string, status *smtp.SMTPStatus)) (*DataCloser, error)
LMTPData is the LMTP-specific version of the Data method. It accepts a callback that will be called for each status response received from the server.
Status callback will receive a smtp argument for each negative server reply and nil for each positive reply. I/O errors will not be reported using callback and instead will be returned by the Close method of DataCloser. Callback will be called for each successfull Rcpt call done before in the same order.
func (*Client) Mail ¶
Mail issues a MAIL command to the server using the provided email address. If the server supports the 8BITMIME extension, Mail adds the BODY=8BITMIME parameter. This initiates a mail transaction and is followed by one or more Rcpt calls.
If opts is not nil, MAIL arguments provided in the structure will be added to the command. Handling of unsupported options depends on the extension.
If server returns an error, it will be of type *smtp.
func (*Client) MaxMessageSize ¶
MaxMessageSize returns the maximum message size accepted by the server. 0 means unlimited.
If the server doesn't convey this information, ok = false is returned.
func (*Client) Noop ¶
Noop sends the NOOP command to the server. It does nothing but check that the connection to the server is okay.
func (*Client) Quit ¶
Quit sends the QUIT command and closes the connection to the server.
If Quit fails the connection is not closed, Close should be used in this case.
func (*Client) Rcpt ¶
Rcpt issues a RCPT command to the server using the provided email address. A call to Rcpt must be preceded by a call to Mail and may be followed by a Data call or another Rcpt call.
If opts is not nil, RCPT arguments provided in the structure will be added to the command. Handling of unsupported options depends on the extension.
If server returns an error, it will be of type *smtp.
func (*Client) Reset ¶
Reset sends the RSET command to the server, aborting the current mail transaction.
func (*Client) SendMail ¶
SendMail will use an existing connection to send an email from address from, to addresses to, with message r.
This function does not start TLS, nor does it perform authentication. Use DialStartTLS and Auth before-hand if desirable.
The addresses in the to parameter are the SMTP RCPT addresses.
The r parameter should be an RFC 822-style email with headers first, a blank line, and then the message body. The lines of r should be CRLF terminated. The r headers should usually include fields such as "From", "To", "Subject", and "Cc". Sending "Bcc" messages is accomplished by including an email address in the to parameter but not including it in the r headers.
func (*Client) SupportsAuth ¶
SupportsAuth checks whether an authentication mechanism is supported.
func (*Client) TLSConnectionState ¶
func (c *Client) TLSConnectionState() (state tls.ConnectionState, ok bool)
TLSConnectionState returns the client's TLS connection state. The return values are their zero values if STARTTLS did not succeed.
func (*Client) Verify ¶
Verify checks the validity of an email address on the server. If Verify returns nil, the address is valid. A non-nil return does not necessarily indicate an invalid address. Many servers will not verify addresses for security reasons.
If server returns an error, it will be of type *smtp.
type DataCloser ¶
type DataCloser struct { io.WriteCloser // contains filtered or unexported fields }
DataCloser implement an io.WriteCloser with the additional CloseWithResponse function.
func (*DataCloser) Close ¶
func (d *DataCloser) Close() error
func (*DataCloser) CloseWithResponse ¶
func (d *DataCloser) CloseWithResponse() (code int, msg string, err error)