emailszh

package module
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 3 Imported by: 0

README

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

emailszh

Chinese-named emails sending package based on gomail.v2, 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 Builder: Chain-style emails construction 🎯 Rich Recipients: Support To, Cc, and Bcc recipients 📎 Attachment Support: Simple file attachment handling 🔧 SMTP Configuration: Flexible sender configuration with SMTP settings

Installation

go get github.com/yylego/emailszh

Quick Start

Basic Text Emails
package main

import (
    "github.com/yylego/emailszh"
)

func main() {
    // Create sender
    sender := &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 and send emails
    emails := emailszh.New邮件构建器().
        Set标题("Emails Subject").
        Set内容(emailszh.New文本内容("Emails content text")).
        Set发送者(sender).
        Set目标(emailszh.New目标单收件(recipient)).
        Get邮件()

    // Send emails
    err := sender.Sen发邮件(emails)
    if err != nil {
        panic(err)
    }
}
HTML Emails
// Create HTML content
htmlContent := emailszh.New网页内容("<h1>Welcome</h1><p>This is HTML content</p>")

// Build emails
emails := emailszh.New邮件构建器().
    Set标题("HTML Emails").
    Set内容(htmlContent).
    Set发送者(sender).
    Set目标(emailszh.New目标单收件(recipient)).
    Get邮件()

sender.Sen发邮件(emails)
Emails with Attachments
emails := emailszh.New邮件构建器().
    Set标题("Emails with Attachment").
    Set内容(emailszh.New文本内容("Please check the attachment")).
    Set发送者(sender).
    Set目标(emailszh.New目标单收件(recipient)).
    Set附件("/path/to/file.pdf").
    Get邮件()

sender.Sen发邮件(emails)
Multiple Recipients (Cc and Bcc)
// Create multiple recipients
to := emailszh.New接收者("to@example.com", "To User")
cc1 := emailszh.New接收者("cc1@example.com", "CC User 1")
cc2 := emailszh.New接收者("cc2@example.com", "CC User 2")
bcc1 := emailszh.New接收者("bcc1@example.com", "BCC User 1")

// Create target with Cc and Bcc
target := emailszh.New收件目标(
    to,
    []*emailszh.R接收者{cc1, cc2},
    []*emailszh.R接收者{bcc1},
)

emails := emailszh.New邮件构建器().
    Set标题("Emails with Multiple Recipients").
    Set内容(emailszh.New文本内容("Content")).
    Set发送者(sender).
    Set目标(target).
    Get邮件()

sender.Sen发邮件(emails)

API Reference

Sender Types
  • S发送者: Sending information including SMTP configuration
  • S发送者s: Sending list type
  • Get拨号器(): Get SMTP dialer instance
  • Sen发邮件(): Send emails 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
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 gomail message
  • Set标题(): Set emails subject
  • Set内容(): Set emails message content
  • Set发送者(): Set sending info
  • Set接收者(): Set single recipient
  • Set目标(): Set complete recipient target
  • Set抄送至(): Set Cc recipients
  • Set密送至(): Set Bcc recipients
  • Set附件(): Add attachment
  • Get邮件(): Get constructed emails message

SMTP Configuration

Common SMTP settings:

Service SMTP Host Port Security
Gmail smtp.gmail.com 465 SSL
Outlook smtp.office365.com 587 TLS
163 smtp.163.com 465/994 SSL
QQ smtp.qq.com 465 SSL

Note: Most emails services require app-specific passwords instead of account passwords.

Requirements

  • Go 1.25 or higher
  • Dependencies: gomail.v2, zaplog

📄 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 Designed with ease of use in mind via readable naming patterns and comprehensive documentation

emailszh: 采用中文直观命名的邮件发送包 提供直观的接口,支持双语标识符(英文前缀 + 中文后缀) 通过发送、接收和消息构建实现便捷的邮件操作 通过可读的命名模式和全面的文档提升使用便捷性

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New邮件

func New邮件(s标题 string, c内容 *C邮件内容, t目标 *T收件目标) *gomail.Message

New邮件 creates complete emails message with subject, content, and targets Combines construction pattern to configure subject, message content, and recipient targeting Returns configured message that can be sent

New邮件 创建包含主题、内容和目标的完整邮件消息 组合构建模式配置主题、消息内容和收件者目标 返回配置好的消息,可以发送

Types

type C邮件内容

type C邮件内容 struct {
	M类型 string               // Content MIME type (text/html or text/plain) // 内容 MIME 类型(text/html 或 text/plain)
	B正文 string               // Message content text // 消息正文文本
	S设置 []gomail.PartSetting // 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文本内容 创建纯文本格式的邮件内容 返回配置了 text/plain MIME 类型的内容

func New网页内容

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

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

New网页内容 创建 HTML 格式的邮件内容 返回配置了 text/html MIME 类型的内容

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 Supports sending, recipients, subject, content, and attachments configuration

O邮件构建器 代表采用方法链模式的邮件构建 通过流畅接口配置邮件消息属性 支持发送、收件者、主题、正文和附件配置

func New构建器

func New构建器(m邮件 *gomail.Message) *O邮件构建器

New构建器 creates construction instance from existing gomail message Enables wrapping existing messages with construction interface Returns construction instance with wrapped message

New构建器 从现有 gomail 消息创建构建实例 使构建接口能够包装现有消息 返回带有包装消息的构建实例

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邮件() *gomail.Message

Get邮件 retrieves the underlying gomail message Returns configured message that can be sent

Get邮件 获取底层的 gomail 消息 返回配置好的消息,可以发送

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密送至

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

Set密送至 configures blind-cc recipient list Returns instance with support of method chaining

Set密送至 配置密送收件者列表 返回实例以支持方法链

func (*O邮件构建器) Set抄送至

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

Set抄送至 configures carbon-cc recipient list Returns instance with support of method chaining

Set抄送至 配置抄送收件者列表 返回实例以支持方法链

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

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

Set接收者 configures emails recipient information Sets main recipient address and shown name Returns instance with support of method chaining

Set接收者 配置邮件接收者信息 设置主要收件者地址和显示名称 返回实例以支持方法链

func (*O邮件构建器) Set标题

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目标(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 ...gomail.FileSetting) *O邮件构建器

Set附件 attaches file to emails message Supports extra settings via variadic FileSetting params Returns instance with support of method chaining

Set附件 向邮件消息添加附件 通过可变参数 FileSetting 支持额外设置 返回实例以支持方法链

type R接收者

type R接收者 struct {
	M邮箱 string // Receiver mailbox address // 接收者邮箱地址
	N昵称 string // Receiver display name // 接收者显示名称
}

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 receiver list type R接收者s 接收者列表类型

type S发送者

type S发送者 struct {
	M邮箱 string `json:"mailbox"`   // Sender mailbox address // 发送者邮箱地址
	N昵称 string `json:"nickname"`  // Sender display name // 发送者显示名称
	H主机 string `json:"smtp_host"` // SMTP server hostname // SMTP 服务器主机名
	P端口 int    `json:"smtp_port"` // SMTP server port // SMTP 服务器端口
	U账号 string `json:"username"`  // SMTP account username (same as address in many cases) // SMTP 账户用户名(通常与地址相同)
	P密码 string `json:"password"`  // SMTP account password // SMTP 账户密码
}

S发送者 represents emails sending configuration with SMTP settings Contains required information including credentials and SMTP settings Note: SMTP default port is 25, but encrypted connections (SSL/TLS) use port 465/994 Ensure the emails client is configured with the correct port and encryption

S发送者 代表带有 SMTP 设置的邮件发送配置 包含必需信息,包括凭证和 SMTP 设置 注意:SMTP 默认端口是 25,但加密连接(SSL/TLS)使用端口 465/994 确保邮件客户端配置正确的端口和加密方式

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

func (sen *S发送者) Act发邮件(m邮件 *gomail.Message) error

Act发邮件 sends emails message using configured SMTP settings Act means "action", acts as Sen发邮件 alias

Act发邮件 使用配置的 SMTP 设置发送邮件消息 Act 取自英文 action(动作),作为 Sen发邮件 的别名

func (*S发送者) Get拨号器

func (sen *S发送者) Get拨号器() *gomail.Dialer

Get拨号器 creates and returns an SMTP dialer with sending configuration Returns configured dialer that can establish SMTP connections

Get拨号器 使用发送配置创建并返回 SMTP 拨号器 返回配置好的拨号器,可建立 SMTP 连接

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

func (sen *S发送者) Sen发邮件(m邮件 *gomail.Message) error

Sen发邮件 sends emails message using configured SMTP settings Sets sending information and establishes connection to send the message Logs operation results and returns an error if sending fails

Sen发邮件 使用配置的 SMTP 设置发送邮件消息 设置发送信息并建立连接发送消息 记录操作结果,发送失败时返回错误

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

func (sen *S发送者) Xqt发邮件(m邮件 *gomail.Message) 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 sender list type 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收件目标

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 nil with warning if the list is blank

New目标首个收件其余密送 创建以首个接收者作为主收件者、其余作为密送的目标 使用第一个元素作为主要收件者,其余作为密送收件者 如果列表为空则返回 nil 并发出警告

Jump to

Keyboard shortcuts

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