mail

package
v1.16.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorParamEmpty liberr.CodeError = iota + liberr.MinPkgMail
	ErrorMailConfigInvalid
	ErrorMailIORead
	ErrorMailIOWrite
	ErrorMailDateParsing
	ErrorMailSmtpClient
	ErrorMailSenderInit
	ErrorFileOpenCreate
)
View Source
const (
	RecipientTo recipientType = iota
	RecipientCC
	RecipientBCC
)
View Source
const (
	DateTimeLayout = time.RFC1123Z
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Body

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

contents represents the different content parts of an email body.

func NewBody

func NewBody(ct ContentType, body io.Reader) Body

type Config added in v1.8.1

type Config struct {
	// Charset is the charset to use into mail header
	Charset string `json:"charset" yaml:"charset" toml:"charset" mapstructure:"charset" validate:"required"`

	// Subject is the subject of the mail
	Subject string `json:"subject" yaml:"subject" toml:"subject" mapstructure:"subject" validate:"required"`

	// Encoding is the encoding mode for contents of mail
	Encoding string `json:"encoding" yaml:"encoding" toml:"encoding" mapstructure:"encoding" validate:"required"`

	// Priority is priority of the mail
	Priority string `json:"priority" yaml:"priority" toml:"priority" mapstructure:"priority" validate:"required"`

	// Header is list of header couple like key = value to be added into mail header
	Headers map[string]string `json:"headers,omitempty" yaml:"headers,omitempty" toml:"headers,omitempty" mapstructure:"headers,omitempty"`

	// From is the email use for sending the mail.
	// If Sender is not set, it will be used as sender into.
	// If ReplyTo is not set, it will be used for the reply email.
	From string `json:"from" yaml:"from" toml:"from" mapstructure:"from" validate:"required,email"`

	// Sender is used to specify the email show as sender.
	// If From is not set, this value will be used as From email.
	// If ReplyTo is not set, it will be used for the reply email.
	Sender string `json:"sender,omitempty" yaml:"sender,omitempty" toml:"sender,omitempty" mapstructure:"sender,omitempty" validate:"email"`

	// ReplyTo is used to specify the email to use for reply.
	// If From is not set, this value will be used as From email.
	// If Sender is not set, it will be used as sender into.
	ReplyTo string `json:"replyTo,omitempty" yaml:"replyTo,omitempty" toml:"replyTo,omitempty" mapstructure:"replyTo,omitempty" validate:"email"`

	// ReturnPath allow to specify the return path, usefull is the ip sender is not public to specify the method to contact the mail server
	ReturnPath string `json:"returnPath,omitempty" yaml:"returnPath,omitempty" toml:"returnPath,omitempty" mapstructure:"returnPath,omitempty"`

	// To is a list of email who the direct recipient of mail.
	To []string `json:"to,omitempty" yaml:"to,omitempty" toml:"to,omitempty" mapstructure:"to,omitempty" validate:"dive,email"`

	// Cc is a list of email who the copy recipient of mail.
	Cc []string `json:"cc,omitempty" yaml:"cc,omitempty" toml:"cc,omitempty" mapstructure:"cc,omitempty" validate:"dive,email"`

	// Bcc is a list of email who in copy recipient of mail but not listed in any field of the mail or headers of the mail.
	Bcc []string `json:"bcc,omitempty" yaml:"bcc,omitempty" toml:"bcc,omitempty" mapstructure:"bcc,omitempty" validate:"dive,email"`

	// Attach define a list of file to be attached to the mail
	Attach []ConfigFile `json:"attach,omitempty" yaml:"attach,omitempty" toml:"attach,omitempty" mapstructure:"attach,omitempty" validate:"dive"`

	// Inline define a list of file to be attached to the mail, but inline the body of the mail and not as mail attachment
	Inline []ConfigFile `json:"inline,omitempty" yaml:"inline,omitempty" toml:"inline,omitempty" mapstructure:"inline,omitempty" validate:"dive"`
}

func (Config) NewMailer added in v1.8.1

func (c Config) NewMailer() (Mail, liberr.Error)

func (Config) Validate added in v1.8.1

func (c Config) Validate() liberr.Error

type ConfigFile added in v1.8.1

type ConfigFile struct {
	Name string `json:"name" yaml:"name" toml:"name" mapstructure:"name" validate:"required"`
	Mime string `json:"mime" yaml:"mime" toml:"mime" mapstructure:"mime" validate:"required"`
	Path string `json:"path" yaml:"path" toml:"path" mapstructure:"path" validate:"required,file"`
}

type ContentType

type ContentType uint8
const (
	// ContentPlainText sets body type to text/plain in message body.
	ContentPlainText ContentType = iota
	// ContentHTML sets body type to text/html in message body.
	ContentHTML
)

func (ContentType) String

func (c ContentType) String() string

type Email

type Email interface {
	SetFrom(mail string)
	GetFrom() string

	SetSender(mail string)
	GetSender() string

	SetReplyTo(mail string)
	GetReplyTo() string

	SetReturnPath(mail string)
	GetReturnPath() string

	SetRecipients(rt recipientType, rcpt ...string)
	AddRecipients(rt recipientType, rcpt ...string)
	GetRecipients(rt recipientType) []string
}

type Encoding

type Encoding uint8
const (
	// EncodingNone turns off encoding on the message body.
	EncodingNone Encoding = iota

	// EncodingBinary is equal to EncodingNone, but string is set to binary instead of none.
	EncodingBinary

	// EncodingBase64 sets the message body encoding to base64.
	EncodingBase64

	// EncodingQuotedPrintable sets the message body encoding to quoted-printable.
	EncodingQuotedPrintable
)

func ParseEncoding added in v1.8.1

func ParseEncoding(s string) Encoding

func (Encoding) String

func (e Encoding) String() string

type File

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

file represents the files that can be added to the email message.

func NewFile

func NewFile(name string, mime string, data io.ReadCloser) File

type Mail

type Mail interface {
	Clone() Mail

	SetCharset(charset string)
	GetCharset() string

	SetPriority(p Priority)
	GetPriority() Priority

	SetSubject(subject string)
	GetSubject() string

	SetEncoding(enc Encoding)
	GetEncoding() Encoding

	SetDateTime(datetime time.Time)
	GetDateTime() time.Time
	SetDateString(layout, datetime string) error
	GetDateString() string

	AddHeader(key string, values ...string)
	GetHeader(key string) []string
	GetHeaders() textproto.MIMEHeader

	SetBody(ct ContentType, body io.ReadCloser)
	AddBody(ct ContentType, body io.ReadCloser)
	GetBody() []Body

	SetAttachment(name string, mime string, data io.ReadCloser, inline bool)
	AddAttachment(name string, mime string, data io.ReadCloser, inline bool)
	AttachFile(filepath string, data io.ReadCloser, inline bool)
	GetAttachment(inline bool) []File

	Email() Email

	Sender() (Sender, error)
}

func New

func New() Mail

type Priority

type Priority uint8
const (
	// PriorityNormal sets the email priority to normal.
	PriorityNormal Priority = iota
	// PriorityLow sets the email priority to Low.
	PriorityLow
	// PriorityHigh sets the email priority to High.
	PriorityHigh
)

func ParsePriority added in v1.8.1

func ParsePriority(s string) Priority

func (Priority) String

func (p Priority) String() string

type Sender

type Sender interface {
	Close() error
	Send(ctx context.Context, cli libsmtp.SMTP) error
	SendClose(ctx context.Context, cli libsmtp.SMTP) error
}

Jump to

Keyboard shortcuts

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