Documentation ¶
Index ¶
- Constants
- Variables
- func TpReader(r io.Reader) *textproto.Reader
- type Attachment
- type Email
- func (e *Email) Attach(r io.Reader, fileName string, contentType string) (a *Attachment, err error)
- func (e *Email) AttachFile(fileName string) (*Attachment, error)
- func (e *Email) AttachWithHeaders(r io.Reader, fileName string, contentType string, headers textproto.MIMEHeader) (a *Attachment, err error)
- func (e *Email) Bytes() ([]byte, error)
- func (e *Email) Send(addr string, a smtp.Auth) error
- func (e *Email) SendWithStartTLS(addr string, auth smtp.Auth, tlsConfig *tls.Config) error
- func (e *Email) SendWithTLS(addr string, auth smtp.Auth, tlsConfig *tls.Config) error
- type Pool
Constants ¶
const ( MaxLineLength = 76 // MaxLineLength is the maximum line length pre RFC 2045 DefaultContentType = "text/plain; charset=us-ascii" // email.ContentType is email default Content-Type according to RFC 2045, section 5.2 StrFileNameParam = "filename" // mime request file name param StrContentType = "Content-Type" StrContentDisposition = "Content-Disposition" StrReplyTo = "Reply-To" StrSubject = "Subject" StrTo = "To" StrCc = "Cc" StrBcc = "Bcc" StrFrom = "From" StrDate = "Date" StrMessageId = "Message-Id" StrMimeVersion = "MIME-Version" )
Variables ¶
var ( // ErrMissingBoundary is returned when there is no boundary given for multipart entity ErrMissingBoundary = errors.New("no boundary found for multipart entity") // ErrMissingContentType is returned when there is no "Content-Type" header for a MIME entity ErrMissingContentType = errors.New("no Content-Type found for MIME entity") // ErrMustSpecifyMessage is returned when there is email param exist empty ErrMustSpecifyMessage = errors.New("must specify at least one from address and one to address") )
var ( ErrClosed = errors.New("pool closed") ErrTimeout = errors.New("timed out") )
Functions ¶
Types ¶
type Attachment ¶
type Attachment struct { FileName string // fileName ContentType string // content type Header textproto.MIMEHeader // header Content []byte // content HTMLRelated bool }
Attachment is email attachement param type Based on the mime/multipart.FileHeader struct Attachment contains the name, MIMEHeader, and content of the attachment in question
type Email ¶
type Email struct { ReplyTo []string // reply to From string //from To []string // to Bcc []string // bcc Cc []string // cc Subject string // subject Text []byte // text plaintext message (optional) Html []byte // html message (optional) Sender string // override from as SMTP envelope sender (optional) Headers textproto.MIMEHeader // headers Attachments []*Attachment // attachments ReadReceipt []string // read receipt }
Email used for email message type
func NewEmailFromReader ¶
NewEmailFromReader reads a stream of bytes from an io.Reader, r, and returns an email struct containing the parsed data. This function expects the data in RFC 5322 format.
func (*Email) Attach ¶
Attach is used to attach content from an io.Reader to the email. Required params include an io.Reader, the desired fileName for the attachment, and the Content-Type the func will return the create Attachment for reference, as well as nil for the error, if successful.
func (*Email) AttachFile ¶
func (e *Email) AttachFile(fileName string) (*Attachment, error)
AttachFile is used to attach content to the email. it attempts to open the file referenced by fileName and, if successful, creates an attachment. this attachment is then appended to the slice of e.Attachments. the func will then return the Attachment for reference, as well as nil for the error, if successful.
func (*Email) AttachWithHeaders ¶
func (e *Email) AttachWithHeaders(r io.Reader, fileName string, contentType string, headers textproto.MIMEHeader) (a *Attachment, err error)
AttachWithHeaders is used to attach content from an io.Reader to the email. Required parameters include an io.Reader, the desired filename for the attachment, the Content-Type and the original MIME headers. The function will return the created Attachment for reference, as well as nil for the error, if successful.
func (*Email) Bytes ¶
Bytes converts the Email object to []byte including all needed MIMEHeaders, boundaries, etc.
func (*Email) Send ¶
Send an email using the given host and SMTP auth (optional), returns any error thrown by smtp.SendMail This function merges the To, Cc, and Bcc fields and calls the smtp.SendMail function using the Email.Bytes() output as the message
func (*Email) SendWithStartTLS ¶
SendWithStartTLS sends an email over TLS using STARTTLS with an optional TLS config.
The TLS Config is helpful if you need to connect to a host that is used an untrusted certificate.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
func (*Pool) Close ¶
func (p *Pool) Close()
Close immediately changes the pool's state so no new connections will be created, then gets and closes the existing ones as they become available.
func (*Pool) Send ¶
Send sends an email via a connection pulled from the Pool. The timeout may be <0 to indicate no timeout. Otherwise reaching the timeout will produce and error building a connection that occurred while we were waiting, or otherwise ErrTimeout.
func (*Pool) SetHelloHostname ¶
SetHelloHostname optionally sets the hostname that the Go smtp.Client will use when doing a HELLO with the upstream SMTP server. By default, Go uses "localhost" which may not be accepted by certain SMTP servers that demand an FQDN.