Documentation
¶
Index ¶
- Variables
- func LoadTemplates(fsys fs.FS, templates map[string]Template) (map[string]Template, error)
- func RegisterDriver(driver string, factory DriverFactory)
- type Attachment
- type AttachmentOpenError
- type AttachmentSource
- type AttachmentSourceFunc
- type AttemptResult
- type DirectMessage
- type DriverFactory
- type Message
- type Middleware
- type Payload
- type Provider
- type ProviderConfig
- type ProviderResult
- type Request
- type SendResult
- type Sender
- type SenderFunc
- type Template
- type TemplateMap
- type TemplateMessage
- type TemplateRenderer
- type TemplateRendererFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrDriverRequired = errors.New("email: driver is required") ErrUnknownDriver = errors.New("email: unknown driver") )
View Source
var ( ErrMessageRequired = errors.New("email: message is required") ErrTemplateRendererRequired = errors.New("email: template renderer is required") ErrTemplateFSRequired = errors.New("email: template fs is required") ErrTemplateNotFound = errors.New("email: template not found") ErrAttachmentInvalid = errors.New("email: attachment is invalid") ErrAttachmentOpen = errors.New("email: open attachment") )
Functions ¶
func LoadTemplates ¶ added in v0.1.4
func RegisterDriver ¶
func RegisterDriver(driver string, factory DriverFactory)
Types ¶
type Attachment ¶ added in v0.1.16
type Attachment struct {
Name string
ContentType string
Size int64
Source AttachmentSource
}
Attachment 是仅在本次发送期间使用的附件描述。 Source 不参与持久化;队列消费者应根据自己的附件 ID 或对象键重新构造它。
type AttachmentOpenError ¶ added in v0.1.16
AttachmentOpenError 表示附件在 Provider 建立发送连接前无法打开。 调用方可用 errors.Is(err, ErrAttachmentOpen) 判断该错误确定未发送。
func (*AttachmentOpenError) Error ¶ added in v0.1.16
func (e *AttachmentOpenError) Error() string
func (*AttachmentOpenError) Is ¶ added in v0.1.16
func (e *AttachmentOpenError) Is(target error) bool
func (*AttachmentOpenError) Unwrap ¶ added in v0.1.16
func (e *AttachmentOpenError) Unwrap() error
type AttachmentSource ¶ added in v0.1.16
type AttachmentSource interface {
Open(ctx context.Context) (io.ReadCloser, error)
}
AttachmentSource 按发送尝试打开一份新的附件内容流。 Provider 会负责关闭成功打开的流;实现方不得复用已经读取过的 reader。
type AttachmentSourceFunc ¶ added in v0.1.16
type AttachmentSourceFunc func(ctx context.Context) (io.ReadCloser, error)
AttachmentSourceFunc 将函数适配为 AttachmentSource。
func (AttachmentSourceFunc) Open ¶ added in v0.1.16
func (fn AttachmentSourceFunc) Open(ctx context.Context) (io.ReadCloser, error)
type AttemptResult ¶
type AttemptResult struct {
Provider string
Success bool
Result *ProviderResult
Error error
}
type DirectMessage ¶ added in v0.1.4
type DirectMessage struct {
To []string
Cc []string
Bcc []string
Subject string
Text string
HTML string
Headers map[string]string
Attachments []Attachment
}
func (DirectMessage) Resolve ¶ added in v0.1.4
func (m DirectMessage) Resolve(context.Context, TemplateRenderer) (Payload, error)
type DriverFactory ¶
type DriverFactory func(name string, cfg ProviderConfig) (Provider, error)
type Message ¶
type Message interface {
Resolve(ctx context.Context, renderer TemplateRenderer) (Payload, error)
}
type Middleware ¶
type Provider ¶
type Provider interface {
Send(ctx context.Context, payload Payload) (*ProviderResult, error)
Close() error
}
func NewProvider ¶
func NewProvider(name string, cfg ProviderConfig) (Provider, error)
type ProviderConfig ¶
type ProviderConfig struct {
Driver string `mapstructure:"driver" yaml:"driver"`
Host string `mapstructure:"host" yaml:"host"`
Port int `mapstructure:"port" yaml:"port"`
Username string `mapstructure:"username" yaml:"username"`
Password string `mapstructure:"password" yaml:"password"`
FromAddress string `mapstructure:"from_address" yaml:"from_address"`
FromName string `mapstructure:"from_name" yaml:"from_name"`
ReplyTo string `mapstructure:"reply_to" yaml:"reply_to"`
Encryption string `mapstructure:"encryption" yaml:"encryption"`
Auth string `mapstructure:"auth" yaml:"auth"`
Timeout time.Duration `mapstructure:"timeout" yaml:"timeout"`
}
func (ProviderConfig) Clone ¶
func (c ProviderConfig) Clone() ProviderConfig
type ProviderResult ¶
type SendResult ¶
type SendResult struct {
Provider string
Result *ProviderResult
Error error
Attempts []AttemptResult
}
type SenderFunc ¶
type SenderFunc func(ctx context.Context, req Request) (*SendResult, error)
func (SenderFunc) Send ¶
func (fn SenderFunc) Send(ctx context.Context, req Request) (*SendResult, error)
type Template ¶ added in v0.1.4
type Template struct {
Subject string `mapstructure:"subject" yaml:"subject"`
SubjectFile string `mapstructure:"subject_file" yaml:"subject_file"`
Text string `mapstructure:"text" yaml:"text"`
TextFile string `mapstructure:"text_file" yaml:"text_file"`
HTML string `mapstructure:"html" yaml:"html"`
HTMLFile string `mapstructure:"html_file" yaml:"html_file"`
}
type TemplateMap ¶ added in v0.1.4
type TemplateMessage ¶ added in v0.1.4
type TemplateMessage struct {
To []string
Cc []string
Bcc []string
Template string
Data map[string]any
Headers map[string]string
Attachments []Attachment
}
func (TemplateMessage) Resolve ¶ added in v0.1.4
func (m TemplateMessage) Resolve(ctx context.Context, renderer TemplateRenderer) (Payload, error)
type TemplateRenderer ¶ added in v0.1.4
Click to show internal directories.
Click to hide internal directories.