Skip to content

go-zwbc/emailzh

Repository files navigation

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

emailzh

Chinese-named email sending library based on gomail.v2, making email operations intuitive with Chinese API.


CHINESE README

中文说明

Main Features

📧 Chinese API: Intuitive Chinese function and type names ⚡ Fluent Builder: Chain-style email construction 🎯 Rich Recipients: Support To, Cc, and Bcc recipients 📎 Attachment Support: Easy file attachment handling 🔧 SMTP Configuration: Flexible sender configuration with SMTP settings

Installation

go get github.com/go-zwbc/emailzh

Quick Start

Basic Text Email

package main

import (
    "github.com/go-zwbc/emailzh"
)

func main() {
    // Create sender
    sender := &emailzh.S发送者{
        A地址: "[email protected]",
        N昵称: "Sender Name",
        H主机: "smtp.example.com",
        P端口: 465,
        U账号: "[email protected]",
        W密码: "password",
    }

    // Create recipient
    recipient := emailzh.New接收者("[email protected]", "Recipient Name")

    // Build and send email
    email := emailzh.New邮件构建器().
        Set标题("Email Subject").
        Set内容(emailzh.New文本内容("Email body content")).
        Set发送者(sender).
        Set目标(emailzh.New目标单收件(recipient)).
        Get邮件()

    // Send email
    err := sender.Sen发邮件(email)
    if err != nil {
        panic(err)
    }
}

HTML Email

// Create HTML content
htmlContent := emailzh.New网页内容("<h1>Welcome</h1><p>This is HTML content</p>")

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

sender.Sen发邮件(email)

Email with Attachments

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

sender.Sen发邮件(email)

Multiple Recipients (Cc and Bcc)

// Create multiple recipients
to := emailzh.New接收者("[email protected]", "To User")
cc1 := emailzh.New接收者("[email protected]", "CC User 1")
cc2 := emailzh.New接收者("[email protected]", "CC User 2")
bcc1 := emailzh.New接收者("[email protected]", "BCC User 1")

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

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

sender.Sen发邮件(email)

API Reference

Sender Types

  • S发送者: Sender information including SMTP configuration
  • Get拨号器(): Get SMTP dialer
  • Sen发邮件(): Send email message

Recipient Types

  • R接收者: Recipient information (address and name)
  • T收件目标: Complete recipient target (To, Cc, Bcc)
  • New接收者(): Create recipient
  • New目标单收件(): Create target with single recipient
  • New目标单收件和密送(): Create target with To and Bcc
  • New目标首个收件其余密送(): First as To, rest as Bcc

Content Types

  • C邮件内容: Email body content
  • New文本内容(): Create plain text content
  • New网页内容(): Create HTML content

Builder Operations

  • O邮件构建器: Email builder with fluent API
  • Set标题(): Set email subject
  • Set内容(): Set email body content
  • Set发送者(): Set sender
  • Set接收者(): Set single recipient
  • Set目标(): Set complete recipient target
  • Set抄送至(): Set Cc recipients
  • Set密送至(): Set Bcc recipients
  • Set附件(): Add attachment
  • Get邮件(): Get built email 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 email services require app-specific passwords instead of account passwords.

Requirements

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

📄 License

MIT License. See LICENSE.


🤝 Contributing

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

  • 🐛 Found a mistake? Open an issue on GitHub with reproduction steps
  • 💡 Have a feature idea? Create an issue to discuss the suggestion
  • 📖 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 and use significant commit messages
  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! 🎉🎉🎉

About

使用go语言收发邮件。该组织下所有项目均使用中文编程。

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published