mailer

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotInitialized = fmt.Errorf("mailer is not initialized")
	ErrInvalidConfig  = fmt.Errorf("invalid mail config")
)

预定义错误

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Name     string // 附件文件名(展示名称)
	FilePath string // 附件文件路径
}

Attachment 邮件附件

type Config

type Config struct {
	Host        string // SMTP 服务器地址
	Port        int    // SMTP 端口
	Username    string // SMTP 用户名
	Password    string // SMTP 密码
	FromAddress string // 发件人地址
	FromName    string // 发件人名称
	UseTLS      bool   // 是否启用 TLS
}

Config 邮件配置

func (Config) Validate

func (c Config) Validate() error

Validate 校验邮件配置是否合法

type Mailer

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

Mailer 邮件发送器,封装 go-mail 提供通用邮件发送能力

func NewMailer

func NewMailer(cfg Config, log logger.Logger) *Mailer

NewMailer 创建邮件发送器 当 cfg.Host 为空或配置校验失败时返回空 Mailer(发送操作返回 ErrNotInitialized)

func (*Mailer) Close

func (m *Mailer) Close() error

Close 关闭邮件客户端,释放连接资源。 关闭后 Mailer 不可再使用,再次调用 Send 将返回 ErrNotInitialized。 可安全多次调用。

func (*Mailer) Send

func (m *Mailer) Send(to []string, subject, body string) error

Send 发送纯文本邮件

func (*Mailer) SendHTML

func (m *Mailer) SendHTML(to []string, subject, htmlBody string) error

SendHTML 发送 HTML 邮件

func (*Mailer) SendMessage

func (m *Mailer) SendMessage(msg *Message) error

SendMessage 发送自定义邮件,支持抄送、密送、附件、回复地址等扩展功能

type Message

type Message struct {
	To          []string     // 收件人列表
	Cc          []string     // 抄送列表
	Bcc         []string     // 密送列表
	Subject     string       // 邮件主题
	TextBody    string       // 纯文本正文
	HTMLBody    string       // HTML 正文
	ReplyTo     string       // 回复地址
	Attachments []Attachment // 附件列表
}

Message 邮件消息,支持抄送、密送、附件、回复地址等扩展功能

Jump to

Keyboard shortcuts

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