emailszh

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

emailszh

Chinese-named emails sending package based on github.com/wneessen/go-mail, making emails operations intuitive with Chinese API.


CHINESE README

中文说明

DISCLAIMER

Writing Go code in Chinese is a viable technique, but something to avoid in production engineering. This approach should not be used in serious and business settings. Teams and companies that embrace it could face contempt from peers and negative judgment across the profession. In business companies, this practice is even more prone to becoming a target of public criticism. This project is dedicated to research and academic studies. Do not use this approach in production.

Main Features

  • 📧 Chinese API: Intuitive Chinese function and type names
  • ⚡ Fluent Construction: Chain methods to compose messages, a wrong address comes back as an error at the end
  • 🎯 Rich Recipients: Support To, Cc, and Bcc recipients
  • 📎 Attachment Support: Simple file attachment handling
  • 🔒 Safe Sending: Each SMTP step has a timeout, the connect step takes a context, and plain text is refused

Installation

go get github.com/yylego/emailszh

Quick Start

Basic Text Emails
package main

import (
    "context"

    "github.com/yylego/emailszh"
)

func main() {
    // Configure the sending account
    account := &emailszh.S发送者{
        M邮箱: "sender@example.com",
        N昵称: "Sender Name",
        H主机: "smtp.example.com",
        P端口: 465,
        U账号: "sender@example.com",
        P密码: "password",
    }

    // Create recipient
    recipient := emailszh.New接收者("recipient@example.com", "Recipient Name")

    // Build the message, a wrong address comes back here
    emails, err := emailszh.New邮件构建器().
        Set主题("Emails Subject").
        Set内容(emailszh.New文本内容("Emails content text")).
        Set目标(emailszh.New目标单收件(recipient)).
        Get邮件()
    if err != nil {
        panic(err)
    }

    // Send emails, the From field comes from the sending account
    if err := account.Sen发邮件(context.Background(), emails); err != nil {
        panic(err)
    }
}
HTML Emails
emails, err := emailszh.New邮件("HTML Emails", emailszh.New网页内容("<h1>Welcome</h1><p>This is HTML content</p>"), emailszh.New目标单收件(recipient))
if err != nil {
    panic(err)
}
err = account.Sen发邮件(ctx, emails)
Emails with Attachments
emails, err := emailszh.New邮件构建器().
    Set主题("Emails with Attachment").
    Set内容(emailszh.New文本内容("Please check the attachment")).
    Set目标(emailszh.New目标单收件(recipient)).
    Set附件("/path/to/file.pdf").
    Get邮件()
Multiple Recipients (Cc and Bcc)
target := emailszh.New收件目标(
    emailszh.New接收者("to@example.com", "To Person"),
    emailszh.R接收者s{emailszh.New接收者("cc1@example.com", "CC Person 1"), emailszh.New接收者("cc2@example.com", "CC Person 2")},
    emailszh.R接收者s{emailszh.New接收者("bcc1@example.com", "BCC Person 1")},
)
emails, err := emailszh.New邮件("Emails with Multiple Recipients", emailszh.New文本内容("Content"), target)
Timeout and Client Options

Sen发邮件 takes go-mail client options following the message, each one replaces the default of the same kind (implicit TLS stays on, go-mail has no option that turns it off):

err := account.Sen发邮件(ctx, emails, mail.WithTimeout(30*time.Second))

API Reference

Sending Configuration
  • S发送者: Sending information including SMTP configuration
  • S发送者s: Sending list type
  • E加密方式: Encryption kind, E端口决定 (blank, port 465 uses implicit TLS and the others use STARTTLS), E隐式加密 ("tls", implicit TLS), E显式加密 ("starttls", STARTTLS)
  • New客户端(): Create a configured go-mail *mail.Client
  • Sen发邮件(): Set the From field and send the message
  • Xqt发邮件(): Alias of Sen发邮件
  • Act发邮件(): Alias of Sen发邮件
Recipient Types
  • R接收者: Recipient information (address and name)
  • R接收者s: Recipient list type
  • T收件目标: Complete recipient target (To, Cc, Bcc)
  • New接收者(): Create recipient instance
  • New收件目标(): Create target with To, Cc, and Bcc
  • New目标单收件(): Create target with single recipient
  • New目标单收件和密送(): Create target with To and Bcc
  • New目标首个收件其余密送(): First as To, rest as Bcc, returns an error when the list is blank
Content Types
  • C邮件内容: Emails message content
  • New文本内容(): Create plain text content
  • New网页内容(): Create HTML content
Message Creation
  • New邮件(): Create complete emails message with subject, content, and target
Construction Operations
  • O邮件构建器: Emails construction with fluent API
  • New邮件构建器(): Create new construction instance
  • New构建器(): Create construction from existing go-mail message
  • Set主题(): Set emails subject
  • Set内容(): Set emails message content
  • Set发送者(): Set sending info
  • Set收件者(): Set the main recipient (To), a message sent to Bcc recipients alone skips it
  • Set目标(): Set complete recipient target
  • Set抄送者(): Set Cc recipients, a blank list clears them
  • Set密送者(): Set Bcc recipients, a blank list clears them
  • Set附件(): Add attachment
  • Get邮件(): Get constructed emails message, with the first address fault met

SMTP Configuration

Common SMTP settings:

Service SMTP Host Port E加密
Gmail smtp.gmail.com 465 blank, E隐式加密 works too
Outlook smtp.office365.com 587 blank, E显式加密 works too
163 smtp.163.com 465/994 E隐式加密 (994 needs it)
QQ smtp.qq.com 465 blank, E隐式加密 works too

Note: Most emails services require app-specific passwords instead of account passwords. Login picks the strongest mechanism the SMTP host offers, PLAIN and LOGIN included. Sending fails when the SMTP host cannot encrypt the connection, plain text is not used. ctx limits the connect step; once connected, each SMTP step gets its own timeout, 15 seconds unless mail.WithTimeout sets it, so the whole send can run past one timeout.

Requirements

  • Go 1.27+
  • Dependencies: github.com/wneessen/go-mail

📄 License

MIT License - see LICENSE.


💬 Contact & Feedback

Contributions are welcome! Report bugs, suggest features, and contribute code:

  • 🐛 Mistake reports? Open an issue on GitHub with reproduction steps
  • 💡 Fresh ideas? Create an issue to discuss
  • 📖 Documentation confusing? Report it so we can improve
  • 🚀 Need new features? Share the use cases to help us understand requirements
  • ⚡ Performance issue? Help us optimize through reporting slow operations
  • 🔧 Configuration problem? Ask questions about complex setups
  • 📢 Follow project progress? Watch the repo to get new releases and features
  • 🌟 Success stories? Share how this package improved the workflow
  • 💬 Feedback? We welcome suggestions and comments

🔧 Development

New code contributions, follow this process:

  1. Fork: Fork the repo on GitHub (using the webpage UI).
  2. Clone: Clone the forked project (git clone https://github.com/yourname/repo-name.git).
  3. Navigate: Navigate to the cloned project (cd repo-name)
  4. Branch: Create a feature branch (git checkout -b feature/xxx).
  5. Code: Implement the changes with comprehensive tests
  6. Testing: (Golang project) Ensure tests pass (go test ./...) and follow Go code style conventions
  7. Documentation: Update documentation to support client-facing changes
  8. Stage: Stage changes (git add .)
  9. Commit: Commit changes (git commit -m "Add feature xxx") ensuring backward compatible code
  10. Push: Push to the branch (git push origin feature/xxx).
  11. PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.

Please ensure tests pass and include relevant documentation updates.


🌟 Support

Welcome to contribute to this project via submitting merge requests and reporting issues.

Project Support:

  • ⭐ Give GitHub stars if this project helps you
  • 🤝 Share with teammates and (golang) programming friends
  • 📝 Write tech blogs about development tools and workflows - we provide content writing support
  • 🌟 Join the ecosystem - committed to supporting open source and the (golang) development scene

Have Fun Coding with this package! 🎉🎉🎉

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func New邮件

func New邮件(s主题 string, c内容 *C邮件内容, t目标 *T收件目标) (*mail.Msg, error)

New邮件 creates complete emails message with subject, content, and targets The From field is set when sending, see S发送者.Sen发邮件 Returns an error when a recipient address fails to parse

New邮件 创建包含主题、内容和目标的完整邮件消息 发件人在发送时设置,见 S发送者.Sen发邮件 收件地址解析失败时返回错误

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 格式的消息

func New文本内容

func New文本内容(s内容 string) *C邮件内容

New文本内容 creates plain text formatted emails content Returns content configured with text/plain MIME type

New文本内容 创建纯文本格式的邮件内容 返回 MIME 类型为 text/plain 的内容

func New网页内容

func New网页内容(s内容 string) *C邮件内容

New网页内容 creates HTML formatted emails content Returns content configured with text/html MIME type

New网页内容 创建 HTML 格式的邮件内容 返回 MIME 类型为 text/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构建器

func New构建器(m邮件 *mail.Msg) *O邮件构建器

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邮件

func (op *O邮件构建器) Get邮件() (*mail.Msg, error)

Get邮件 returns the message, and the first fault met while setting it Get邮件 返回邮件,以及设置过程中遇到的第一个错误

func (*O邮件构建器) Set主题 added in v0.0.1

func (op *O邮件构建器) Set主题(s主题 string) *O邮件构建器

Set主题 configures emails subject line Returns instance with support of method chaining

Set主题 配置邮件主题行 返回实例以支持方法链

func (*O邮件构建器) Set内容

func (op *O邮件构建器) Set内容(c内容 *C邮件内容) *O邮件构建器

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发送者

func (op *O邮件构建器) Set发送者(s发送者 *S发送者) *O邮件构建器

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

func (op *O邮件构建器) Set密送者(s接收者s R接收者s) *O邮件构建器

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

func (op *O邮件构建器) Set抄送者(s接收者s R接收者s) *O邮件构建器

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

func (op *O邮件构建器) Set收件者(r接收者 *R接收者) *O邮件构建器

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目标

func (op *O邮件构建器) Set目标(t目标 *T收件目标) *O邮件构建器

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接收者 代表邮件接收信息 包含收件地址和显示名称

func New接收者

func New接收者(s地址 string, s昵称 string) *R接收者

New接收者 creates a new emails receiving instance Returns configured instance with address and shown name

New接收者 创建新的邮件接收实例 返回配置好的实例,包含地址和显示名称

type R接收者s

type R接收者s []*R接收者

R接收者s lists recipients R接收者s 接收者列表类型

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发邮件

func (sen *S发送者) Act发邮件(ctx context.Context, m邮件 *mail.Msg, opts ...mail.Option) error

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

func (sen *S发送者) New客户端(opts ...mail.Option) (*mail.Client, error)

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发邮件

func (sen *S发送者) Sen发邮件(ctx context.Context, m邮件 *mail.Msg, opts ...mail.Option) error

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 失败不会把它报成失败

func (*S发送者) Xqt发邮件

func (sen *S发送者) Xqt发邮件(ctx context.Context, m邮件 *mail.Msg, opts ...mail.Option) error

Xqt发邮件 sends emails message using configured SMTP settings Xqt is the pinyin abbreviation of 执行(execute), acts as Sen发邮件 alias

Xqt发邮件 使用配置的 SMTP 设置发送邮件消息 Xqt 是"执行"的拼音缩写,作为 Sen发邮件 的别名

type S发送者s

type S发送者s []*S发送者

S发送者s lists sending configurations S发送者s 发送者列表类型

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收件目标

func New收件目标(r接收者 *R接收者, s抄送者s []*R接收者, s密送者s []*R接收者) *T收件目标

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目标单收件

func New目标单收件(r接收者 *R接收者) *T收件目标

New目标单收件 creates emails target with single main recipient Returns target with one main recipient and blank Cc/Bcc lists

New目标单收件 创建包含单个主要收件者的邮件目标 返回包含一个主要收件者和空白 Cc/Bcc 列表的目标

func New目标单收件和密送

func New目标单收件和密送(r接收者 *R接收者, s密送者s []*R接收者) *T收件目标

New目标单收件和密送 creates emails target with main recipient and blind-cc list Returns target with one main recipient and multiple Bcc recipients

New目标单收件和密送 创建包含主要收件者和密送列表的邮件目标 返回包含一个主要收件者和多个密送收件者的目标

func New目标首个收件其余密送

func New目标首个收件其余密送(s接收者s R接收者s) (*T收件目标, error)

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目标首个收件其余密送 创建以首个接收者作为主收件者、其余作为密送的目标 使用第一个元素作为主要收件者,其余作为密送收件者 列表为空时返回错误

Jump to

Keyboard shortcuts

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