Documentation
¶
Index ¶
- func IsPermanent(err error) bool
- func JoinAddresses(addrs []EmailAddress) string
- func JoinFormattedAddresses(addrs []EmailAddress, charset string) string
- func SendMail(addr string, a smtp.Auth, msg *Email) error
- func Split(addr string) (string, string)
- func WriteEncodedBody(p io.Writer, body []byte, encoding string) (err error)
- type Email
- func (e *Email) AddAttachment(filename, contentType string, body []byte)
- func (e *Email) AddEmbeddedImage(filename, contentType, contentID string, body []byte)
- func (e *Email) ContentType() string
- func (e *Email) IsMultiPart() bool
- func (e *Email) LoadAttachment(path string) error
- func (e *Email) Write(w io.Writer) error
- type EmailAddress
- type Header
- type Headers
- type Part
- type SendBulkReport
- type SendBulkReportItem
- type Session
- func (c *Session) Auth() error
- func (c *Session) Close() error
- func (c *Session) Data() (io.WriteCloser, error)
- func (c *Session) Extension(ext string) (bool, string)
- func (c *Session) Hello(localName string) error
- func (c *Session) Mail(from string) error
- func (c *Session) MailAndRcpt(msg *Email) error
- func (c *Session) Quit() error
- func (c *Session) Rcpt(to string) error
- func (c *Session) Reset() error
- func (c *Session) SendMessageBulk(messages []*Email) (SendBulkReport, error)
- func (c *Session) SendSingleMessage(msg *Email) error
- func (c *Session) StartSession() error
- func (c *Session) StartTLS(config *tls.Config) error
- func (c *Session) TLSConnectionState() (state tls.ConnectionState, ok bool)
- func (c *Session) Verify(addr string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsPermanent ¶
IsPermanent returns true if the error is permanent, and false otherwise. If it can't tell, it returns false.
func JoinAddresses ¶
func JoinAddresses(addrs []EmailAddress) string
JoinAddresses produces a concatenation of email addresses
func JoinFormattedAddresses ¶
func JoinFormattedAddresses(addrs []EmailAddress, charset string) string
JoinFormattedAddresses produces a concatenation of formatted email addresses
func SendMail ¶
SendMail connects to the server at addr, switches to TLS if possible, authenticates with the optional mechanism a if possible, and then sends an email from address from, to addresses to, with message msg. The addr must include a port, as in "mail.example.com:smtp".
Types ¶
type Email ¶
type Email struct { From EmailAddress `json:"from"` To []EmailAddress `json:"to"` Cc []EmailAddress `json:"cc"` Bcc []EmailAddress `json:"bcc"` Subject string `json:"subject"` Headers Headers `json:"headers"` // Extended SMTP headers Text string `json:"text"` HTML string `json:"html"` AMP string `json:"amp"` Encoding string `json:"encoding"` // "quoted-printable", "base64", "8bit" CharSet string `json:"charset"` // "UTF-8", "iso-8859-1", ... MessageID string `json:"message_id"` ReplyTo EmailAddress `json:"reply_to"` Recipient string `json:"recipient"` ReturnPath string `json:"returnpath"` Sender string `json:"sender"` Attachments []*Part `json:"attachments"` Images []*Part `json:"images"` Sanitize bool `json:"sanitize"` }
Email rapresents an email message.
func NewEmail ¶
func NewEmail(from EmailAddress, to []EmailAddress, subject, html, text string) *Email
NewEmail creates a new email message using default settings.
func (*Email) AddAttachment ¶
AddAttachment adds an attachment to the message.
func (*Email) AddEmbeddedImage ¶
AddEmbeddedImage adds an embedded image to the message.
func (*Email) ContentType ¶
ContentType detects the message content type.
func (*Email) IsMultiPart ¶
IsMultiPart detects if the message is multipart.
func (*Email) LoadAttachment ¶
LoadAttachment attachs a file to the message.
type EmailAddress ¶
EmailAddress contains an email name and address.
func (*EmailAddress) FormatAddress ¶
func (ad *EmailAddress) FormatAddress(charset string) string
FormatAddress formats an address and a name as a valid RFC 5322 address.
func (*EmailAddress) String ¶
func (ad *EmailAddress) String() string
type Headers ¶
type Headers []*Header
Headers is a list of email headers.
func (Headers) AddHeaders ¶
AddHeaders adds a list of headers
func (Headers) GetHeader ¶
GetHeader returns the first occurrance of the header with this name or nil if not found.
func (Headers) GetHeaders ¶
GetHeaders returns all the occurrence of the header with this name.
type Part ¶
type Part struct { Filename string `json:"filename"` ContentType string `json:"content_type"` ContentDisposition string `json:"content_disposition"` // "attachment" Encoding string `json:"encoding"` // "quoted-printable", "base64", "8bit" CharSet string `json:"charset"` // "utf-8", "iso-8859-1", ... ContentID string `json:"content_id"` Body []byte `json:"body"` }
Part is used for including file and embedded image.
type SendBulkReport ¶
type SendBulkReport []SendBulkReportItem
SendBulkReport contains the list of the report items.
type SendBulkReportItem ¶
SendBulkReportItem represents the outcome of a single sending.
type Session ¶
type Session struct { // Text is the textproto.Conn used by the Client. It is exported to allow for // clients to add extensions. Text *textproto.Conn // contains filtered or unexported fields }
Session represents a client connection to an SMTP server.
func NewSession ¶
NewSession returns a new client Session connected to an SMTP server at host. The host must include a port, as in "mail.example.com:smtp".
func NewSessionUsingConnection ¶
NewSessionUsingConnection returns a new Session using an existing connection and host as a server name to be used when authenticating.
func (*Session) Auth ¶
Auth authenticates a client using the provided authentication mechanism. A failed authentication closes the connection. Only servers that advertise the AUTH extension support this function.
func (*Session) Data ¶
func (c *Session) Data() (io.WriteCloser, 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.
func (*Session) 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 (*Session) 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.
func (*Session) 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.
func (*Session) MailAndRcpt ¶
MailAndRcpt issues MAIL FROM and RCPT TO commands, in sequence. It will check the addresses, decide if SMTPUTF8 is needed, and apply the necessary transformations. If the message ReturnPath is setted, it will be used as MAIL FROM address. If the message Recipient is setted, it will be used ad the only RCPT TO address.
func (*Session) 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.
func (*Session) Reset ¶
Reset sends the RSET command to the server, aborting the current mail transaction.
func (*Session) SendMessageBulk ¶
func (c *Session) SendMessageBulk(messages []*Email) (SendBulkReport, error)
SendMessageBulk sends a list of messages to an SMTP server using the same connection and at the end closes the session and the connection.
func (*Session) SendSingleMessage ¶
SendSingleMessage sends a single email to the recipient. The method requires that the session is open and leaves it open.
func (*Session) StartSession ¶
StartSession opens an SMTP session.
func (*Session) StartTLS ¶
StartTLS sends the STARTTLS command and encrypts all further communication. Only servers that advertise the STARTTLS extension support this function.
func (*Session) TLSConnectionState ¶
func (c *Session) 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.