email

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

README

framework-email

Go framework package for email.

Installation

go get github.com/go-anyway/framework-email@v1.0.0

Usage

See documentation for usage examples.

License

Apache License 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled     bool               `yaml:"enabled" env:"EMAIL_ENABLED" default:"true"`
	Host        string             `yaml:"host" env:"EMAIL_HOST" default:"localhost"`
	Port        int                `yaml:"port" env:"EMAIL_PORT" default:"587"`
	Username    string             `yaml:"username" env:"EMAIL_USERNAME" required:"true"`
	Password    string             `yaml:"password" env:"EMAIL_PASSWORD" required:"true"`
	From        string             `yaml:"from" env:"EMAIL_FROM" required:"true"`
	EnableTLS   bool               `yaml:"enable_tls" env:"EMAIL_ENABLE_TLS" default:"true"`
	Timeout     pkgConfig.Duration `yaml:"timeout" env:"EMAIL_TIMEOUT" default:"30s"`
	EnableTrace bool               `yaml:"enable_trace" env:"EMAIL_ENABLE_TRACE" default:"true"`
}

Config 邮件配置结构体(用于从配置文件创建)

func (*Config) TimeoutDuration

func (c *Config) TimeoutDuration() time.Duration

TimeoutDuration 返回 time.Duration 类型的 Timeout

func (*Config) ToOptions

func (c *Config) ToOptions() (*Options, error)

ToOptions 转换为 Options

func (*Config) Validate

func (c *Config) Validate() error

Validate 验证邮件配置

type EmailClient

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

EmailClient 邮件客户端

func NewEmail

func NewEmail(opts *Options) (*EmailClient, error)

NewEmail 根据给定的选项创建一个新的邮件客户端实例

func (*EmailClient) Send

func (e *EmailClient) Send(ctx context.Context, msg *Message) error

Send 发送邮件(自动处理追踪)

func (*EmailClient) SendHTML

func (e *EmailClient) SendHTML(ctx context.Context, to []string, subject, html string) error

SendHTML 发送 HTML 邮件

func (*EmailClient) SendSimple

func (e *EmailClient) SendSimple(ctx context.Context, to []string, subject, body string) error

SendSimple 发送简单邮件(只包含收件人、主题和正文)

type Message

type Message struct {
	To      []string // 收件人列表
	Cc      []string // 抄送列表
	Bcc     []string // 密送列表
	Subject string   // 主题
	Body    string   // 正文(文本格式)
	HTML    string   // 正文(HTML 格式,如果设置了 HTML,则优先使用 HTML)
}

Message 邮件消息结构

type Options

type Options struct {
	Host        string        // SMTP 主机地址
	Port        int           // SMTP 端口
	Username    string        // SMTP 用户名
	Password    string        // SMTP 密码
	From        string        // 发件人邮箱地址
	EnableTLS   bool          // 是否启用 TLS
	Timeout     time.Duration // 连接超时
	EnableTrace bool          // 是否启用邮件发送追踪
}

Options 结构体定义了邮件客户端的配置选项(内部使用)

Jump to

Keyboard shortcuts

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