Documentation
¶
Overview ¶
Package emailszh: Emails sending package with Chinese-intuitive naming conventions Provides intuitive interfaces supporting two-language identifiers (English prefix + Chinese suffix) Enables simple emails operations with sending, receiving, and message building Built on github.com/wneessen/go-mail: sending takes a context, the connection must be encrypted, and a timeout is set
emailszh: 采用中文直观命名的邮件发送包 提供直观的接口,支持双语标识符(英文前缀 + 中文后缀) 通过发送、接收和消息构建实现便捷的邮件操作 基于 github.com/wneessen/go-mail,发送时接收 ctx,默认强制加密并带超时
Index ¶
- func New邮件(s主题 string, c内容 *C邮件内容, t目标 *T收件目标) (*mail.Msg, error)
- type C邮件内容
- type E加密方式
- type O邮件构建器
- func (op *O邮件构建器) Get邮件() (*mail.Msg, error)
- func (op *O邮件构建器) Set主题(s主题 string) *O邮件构建器
- func (op *O邮件构建器) Set内容(c内容 *C邮件内容) *O邮件构建器
- func (op *O邮件构建器) Set发送者(s发送者 *S发送者) *O邮件构建器
- func (op *O邮件构建器) Set密送者(s接收者s R接收者s) *O邮件构建器
- func (op *O邮件构建器) Set抄送者(s接收者s R接收者s) *O邮件构建器
- func (op *O邮件构建器) Set收件者(r接收者 *R接收者) *O邮件构建器
- func (op *O邮件构建器) Set目标(t目标 *T收件目标) *O邮件构建器
- func (op *O邮件构建器) Set附件(s附件路径 string, settings ...mail.FileOption) *O邮件构建器
- type R接收者
- type R接收者s
- type S发送者
- func (sen *S发送者) Act发邮件(ctx context.Context, m邮件 *mail.Msg, opts ...mail.Option) error
- func (sen *S发送者) New客户端(opts ...mail.Option) (*mail.Client, error)
- func (sen *S发送者) Sen发邮件(ctx context.Context, m邮件 *mail.Msg, opts ...mail.Option) error
- func (sen *S发送者) Xqt发邮件(ctx context.Context, m邮件 *mail.Msg, opts ...mail.Option) error
- type S发送者s
- type T收件目标
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type C邮件内容 ¶
type C邮件内容 struct {
M类型 mail.ContentType // Content MIME type, mail.TypeTextHTML and mail.TypeTextPlain // 内容 MIME 类型(mail.TypeTextHTML 或 mail.TypeTextPlain)
B正文 string // Message content text // 消息正文文本
S设置 []mail.PartOption // Part settings in message formatting // 消息格式化的部分设置
}
C邮件内容 represents emails message content configuration Contains content type, text/HTML content, and formatting settings Supports both plain text and HTML formatted messages
C邮件内容 代表邮件消息内容配置 包含内容类型、文本/HTML 内容和格式设置 支持纯文本和 HTML 格式的消息
type E加密方式 ¶ added in v0.0.1
type E加密方式 string
E加密方式 picks how the SMTP connection gets encrypted, the two kinds are implicit TLS and STARTTLS (RFC 8314), neither sends in plain text The values match the names SMTP settings pages use, so a JSON config can hold them as is
E加密方式 决定 SMTP 连接怎么加密,两种是隐式 TLS 和显式 TLS(即 STARTTLS,见 RFC 8314),都不会退回明文发送 取值与邮箱设置页面的叫法一致,JSON 配置里可以原样保存
const ( E端口决定 E加密方式 = "" // Port 465 uses implicit TLS, the others use STARTTLS // 465 端口用隐式加密,其他端口用 STARTTLS E隐式加密 E加密方式 = "tls" // Implicit TLS (SSL/TLS) on each port, such as 465 and 994 // 任意端口都用隐式加密(SSL/TLS),一连上就加密,如 465、994 E显式加密 E加密方式 = "starttls" // STARTTLS on each port, such as 587 and 25 // 任意端口都用显式加密(STARTTLS),连上后升级成加密,如 587、25 )
type O邮件构建器 ¶
type O邮件构建器 struct {
// contains filtered or unexported fields
}
O邮件构建器 represents emails message construction with method chaining pattern Enables fluent interface configuration of emails message properties An address that fails to parse is kept as the first fault, and Get邮件 returns it
O邮件构建器 代表采用方法链模式的邮件构建 通过流畅接口配置邮件消息属性 地址解析失败时记下第一个错误,由 Get邮件 返回
func New构建器 ¶
New构建器 creates construction instance from existing go-mail message Enables wrapping existing messages with construction interface Returns construction instance with wrapped message
New构建器 从现有 go-mail 消息创建构建实例 使构建接口能够包装现有消息 返回带有包装消息的构建实例
func New邮件构建器 ¶
func New邮件构建器() *O邮件构建器
New邮件构建器 creates new emails construction instance with fresh message Returns instance that can configure emails properties
New邮件构建器 创建新的邮件构建实例,带有新消息 返回可配置邮件属性的实例
func (*O邮件构建器) Get邮件 ¶
Get邮件 returns the message, and the first fault met while setting it Get邮件 返回邮件,以及设置过程中遇到的第一个错误
func (*O邮件构建器) Set主题 ¶ added in v0.0.1
Set主题 configures emails subject line Returns instance with support of method chaining
Set主题 配置邮件主题行 返回实例以支持方法链
func (*O邮件构建器) Set内容 ¶
Set内容 configures emails content with type and settings Supports both plain text and HTML content types Returns instance with support of method chaining
Set内容 配置邮件内容及其类型和设置 支持纯文本和 HTML 内容类型 返回实例以支持方法链
func (*O邮件构建器) Set发送者 ¶
Set发送者 configures emails sending information Sets both sending address and shown name Returns instance with support of method chaining
Set发送者 配置邮件发送信息 设置发送地址和显示名称 返回实例以支持方法链
func (*O邮件构建器) Set密送者 ¶ added in v0.0.1
Set密送者 configures blind-cc recipient list, a blank list clears it Bcc recipients get the message but are not written in the message headers Returns instance with support of method chaining
Set密送者 配置密送收件者列表,空列表清除密送 密送收件者能收到邮件,但不会写进邮件头 返回实例以支持方法链
func (*O邮件构建器) Set抄送者 ¶ added in v0.0.1
Set抄送者 configures carbon-cc recipient list, a blank list clears it Returns instance with support of method chaining
Set抄送者 配置抄送收件者列表,空列表清除抄送 返回实例以支持方法链
func (*O邮件构建器) Set收件者 ¶ added in v0.0.1
Set收件者 configures the main recipient (To) Sets main recipient address and shown name, a missing recipient is a fault A message sent to Bcc recipients alone skips this and calls Set密送者 Returns instance with support of method chaining
Set收件者 配置主要收件者(To) 设置主要收件者地址和显示名称,没传接收者算错误 只发给密送收件者的邮件不调用这个,直接调用 Set密送者 返回实例以支持方法链
func (*O邮件构建器) Set目标 ¶
Set目标 configures complete emails targeting with recipient types Sets main recipient, carbon-cc (Cc), and blind-cc (Bcc) lists Returns instance with support of method chaining
Set目标 配置完整邮件目标及收件者类型 设置主要收件者、抄送(Cc)和密送(Bcc)列表 返回实例以支持方法链
func (*O邮件构建器) Set附件 ¶
func (op *O邮件构建器) Set附件(s附件路径 string, settings ...mail.FileOption) *O邮件构建器
Set附件 attaches file to emails message Supports extra settings via variadic go-mail FileOption params A path that does not exist comes back from Get邮件 as a fault, so the message never goes out without the file Returns instance with support of method chaining
Set附件 向邮件消息添加附件 通过可变参数 go-mail FileOption 支持额外设置 路径不存在时由 Get邮件 返回错误,不会发出一封缺了附件的邮件 返回实例以支持方法链
type R接收者 ¶
type R接收者 struct {
M邮箱 string // Recipient address // 接收者邮箱地址
N昵称 string // Recipient name shown in the message // 接收者显示名称
}
R接收者 represents emails receiving information Contains recipient address and shown name
R接收者 代表邮件接收信息 包含收件地址和显示名称
type S发送者 ¶
type S发送者 struct {
M邮箱 string `json:"mailbox"` // Address used in the From field // 发送者邮箱地址
N昵称 string `json:"nickname"` // Name shown in the From field // 发送者显示名称
H主机 string `json:"smtp_host"` // SMTP hostname // SMTP 服务器主机名
P端口 int `json:"smtp_port"` // SMTP connection port // SMTP 服务器端口
U账号 string `json:"username"` // SMTP account username (often the account address) // SMTP 账户用户名(通常与地址相同)
P密码 string `json:"password"` // SMTP account password // SMTP 账户密码
E加密 E加密方式 `json:"tls_mode"` // Encryption kind, blank picks it from the port // 加密方式,不填按端口决定
}
S发送者 represents emails sending configuration with SMTP settings Contains the address shown in From, the SMTP host, the account and the encryption Login picks the strongest mechanism the SMTP host offers, PLAIN and LOGIN included
S发送者 代表带有 SMTP 设置的邮件发送配置 包含发件地址、SMTP 服务器、登录账号和加密方式 登录方式自动选服务器支持的最强一种,PLAIN、LOGIN 都支持
func (*S发送者) Act发邮件 ¶
Act发邮件 sends emails message using configured SMTP settings Act means "action", acts as Sen发邮件 alias
Act发邮件 使用配置的 SMTP 设置发送邮件消息 Act 取自英文 action(动作),作为 Sen发邮件 的别名
func (*S发送者) New客户端 ¶ added in v0.0.1
New客户端 creates a go-mail client with the sending configuration Each option in opts goes in once the defaults are set, so it can replace one of them (such as mail.WithTimeout) Implicit TLS (E隐式加密, and port 465 under E端口决定) stays on regardless of opts, go-mail has no option that turns it off
New客户端 使用发送配置创建 go-mail 客户端 opts 排在默认设置之后,可以替换其中某一项(如 mail.WithTimeout) 隐式加密(E隐式加密,或 E端口决定 下的 465 端口)不受 opts 影响,go-mail 没有关掉它的选项
func (*S发送者) Sen发邮件 ¶
Sen发邮件 sets the From field of the message to this sending account, then connects and sends it ctx limits the connect step; once connected, each SMTP step (greeting, TLS, login, message text) gets its own timeout The timeout is 15 seconds unless mail.WithTimeout in opts sets it, so a host that stops answering cannot hang the send Once the host accepts the message text, the send counts as done: a failing RSET, and a failing QUIT, do not turn it into a fault
Sen发邮件 把邮件的发件人设成这个发送账号,然后连接服务器发送 ctx 管连接这一步;连上以后,每一个 SMTP 步骤(握手、加密、登录、传正文)各有自己的超时 超时默认 15 秒,opts 里传 mail.WithTimeout 可以改,服务器不再应答时发送不会一直卡住 服务器收下正文就算发送成功:随后 RSET 或 QUIT 失败不会把它报成失败
type T收件目标 ¶
type T收件目标 struct {
R收件者 *R接收者 // Main recipient (To) // 主要收件者(To)
R抄送者s R接收者s // Carbon-cc recipients (Cc) // 抄送收件者(Cc)
R密送者s R接收者s // Blind-cc recipients (Bcc) // 密送收件者(Bcc)
}
T收件目标 represents complete emails targeting configuration Contains main recipient, carbon-cc recipients, and blind-cc recipients Supports various emails distribution patterns
T收件目标 代表完整的邮件目标配置 包含主要收件者、抄送收件者和密送收件者 支持多种邮件分发模式
func New收件目标 ¶
New收件目标 creates complete emails targeting with recipient types Supports main recipient, carbon-cc list, and blind-cc list Returns configured target with recipient information
New收件目标 创建完整邮件目标及收件者类型 支持主要收件者、抄送列表和密送列表 返回配置好的目标,包含收件者信息
func New目标单收件 ¶
New目标单收件 creates emails target with single main recipient Returns target with one main recipient and blank Cc/Bcc lists
New目标单收件 创建包含单个主要收件者的邮件目标 返回包含一个主要收件者和空白 Cc/Bcc 列表的目标
func New目标单收件和密送 ¶
New目标单收件和密送 creates emails target with main recipient and blind-cc list Returns target with one main recipient and multiple Bcc recipients
New目标单收件和密送 创建包含主要收件者和密送列表的邮件目标 返回包含一个主要收件者和多个密送收件者的目标
func New目标首个收件其余密送 ¶
New目标首个收件其余密送 creates emails target with first as main and remaining as Bcc Uses first element as main recipient and rest as blind-cc recipients Returns an error when the list is blank
New目标首个收件其余密送 创建以首个接收者作为主收件者、其余作为密送的目标 使用第一个元素作为主要收件者,其余作为密送收件者 列表为空时返回错误