email

package
v1.45.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSMTPPort = 465 // 465 使用 SSL;587 使用 STARTTLS
	// MaxAttachmentSize 是附件大小上限(25MB)。
	MaxAttachmentSize = 25 * 1024 * 1024
)

默认 SMTP 端口与附件大小上限。

Variables

This section is empty.

Functions

func SetGlobal added in v1.36.0

func SetGlobal(client *Client)

SetGlobal 设置全局客户端(NewSender 成功后自动调用)。

Types

type Client

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

Client 封装 SMTP 发送配置。

func Get added in v1.36.0

func Get() *Client

Get 获取全局邮件客户端;未初始化时返回 nil。

func GetClient

func GetClient(emailCong *MailConnConf) *Client

GetClient 根据配置创建邮件客户端;nil 配置返回空客户端(SendMail 会报错)。

func (*Client) SendMail

func (emailC *Client) SendMail(mailTo []string, subject, body, fileName, filePath string) error

SendMail 发送邮件。 mailTo 支持多人发送;subject 为标题;body 为 HTML 正文。 fileName 与 filePath 同时非空时附带附件(存在性、大小与目录校验)。

type MailConnConf

type MailConnConf struct {
	User  string // 发送人邮箱
	Pass  string // 发送人邮箱的授权码(由邮箱服务商签发)
	Host  string // 邮箱服务器(例如 smtp.qq.com)
	Alias string // 邮箱发送别名
	Port  int    // SMTP 端口;非正数时使用 465(465 使用 SSL,587 使用 STARTTLS)
}

MailConnConf 定义 SMTP 发送配置。 Pass 为敏感字段,禁止写入日志。

Jump to

Keyboard shortcuts

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