camMail

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2020 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

From: https://github.com/jordan-wright/email Datetime: 2020-03-09 17:28:00

From: https://github.com/jordan-wright/email Datetime: 2020-03-09 17:28:00

Index

Constants

View Source
const (
	MaxLineLength = 76 // MaxLineLength is the maximum line length per RFC 2045

)

Variables

View Source
var (
	ErrClosed  = errors.New("pool closed")
	ErrTimeout = errors.New("timed out")
)
View Source
var ErrMissingBoundary = errors.New("No boundary found for multipart entity")

ErrMissingBoundary is returned when there is no boundary given for a multipart entity

View Source
var ErrMissingContentType = errors.New("No Content-Type found for MIME entity")

ErrMissingContentType is returned when there is no "Content-Type" header for a MIME entity

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Filename string
	Header   textproto.MIMEHeader
	Content  []byte
}

Attachment is a struct representing an email attachment. 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
	From        string
	To          []string
	Bcc         []string
	Cc          []string
	Subject     string
	Text        []byte // Plaintext message (optional)
	HTML        []byte // Html message (optional)
	Sender      string // override From as SMTP envelope sender (optional)
	Headers     textproto.MIMEHeader
	Attachments []*Attachment
	ReadReceipt []string
}

Email is the type used for email messages

func NewEmail

func NewEmail() *Email

NewEmail creates an Email, and returns the pointer to it.

func NewEmailFromReader

func NewEmailFromReader(r io.Reader) (*Email, error)

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

func (e *Email) Attach(r io.Reader, filename string, c string) (a *Attachment, err error)

Attach is used to attach content from an io.Reader to the email. Required parameters include an io.Reader, the desired filename for the attachment, and the Content-Type The function will return the created Attachment for reference, as well as nil for the error, if successful.

func (*Email) AttachFile

func (e *Email) AttachFile(filename string) (a *Attachment, err 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 Email.Attachments. The function will then return the Attachment for reference, as well as nil for the error, if successful.

func (*Email) Bytes

func (e *Email) Bytes() ([]byte, error)

Bytes converts the Email object to a []byte representation, including all needed MIMEHeaders, boundaries, etc.

func (*Email) Send

func (e *Email) Send(addr string, a smtp.Auth) error

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) SendWithTLS

func (e *Email) SendWithTLS(addr string, a smtp.Auth, t *tls.Config) error

SendWithTLS sends an email with an optional TLS config. This is helpful if you need to connect to a host that is used an untrusted certificate.

type MailComponent

type MailComponent struct {
	component.Component
	// contains filtered or unexported fields
}

func (*MailComponent) Init

func (*MailComponent) Send

func (comp *MailComponent) Send(subject string, body string, to ...string) error

send mail

func (*MailComponent) Start

func (comp *MailComponent) Start()

on App start

func (*MailComponent) Stop

func (comp *MailComponent) Stop()

before App destroy

type MailComponentConfig

type MailComponentConfig struct {
	component.ComponentConfig

	Email              string // master mail
	Nickname           string // nickname
	Password           string // password
	Host               string // Host. mail server Host. Example: "smtp.qq.com"
	Port               uint16 // post
	Ssl                bool   // whether ssl mode
	DefaultContentType string // default: "Content-Type: text/plain; charset=UTF-8"
}

func NewMailConfig

func NewMailConfig(email string, password string, host string) *MailComponentConfig

new mail component config

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool(address string, count int, auth smtp.Auth, opt_tlsConfig ...*tls.Config) (pool *Pool, err error)

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

func (p *Pool) Send(e *Email, timeout time.Duration) (err error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL