百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

go-simple-mail

> 包管理
开源

用于发送电子邮件的 Golang 包。支持保持活动连接、TLS 和 SSL。适用于批量 SMTP。

696 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

用于发送电子邮件的 Golang 包。支持保持活动连接、TLS 和 SSL。适用于批量 SMTP。

Go Simple Mail

The best way to send emails in Go with SMTP Keep Alive and Timeout for Connect and Send.

IMPORTANT

Examples in this README are for v2.2.0 and above. Examples for older versions can be found here.

Go 1.13+ is required.

Breaking change in 2.2.0: The signature of SetBody and AddAlternative used to accept strings ("text/html" and "text/plain") and not require on of the contentType constants (TextHTML or TextPlain). Upgrading, while not quite following semantic versioning, is quite simple:

  email := mail.NewMSG()
- email.SetBody("text/html", htmlBody)
- email.AddAlternative("text/plain", plainBody)
+ email.SetBody(mail.TextHTML, htmlBody)
+ email.AddAlternative(mail.TextPlain, plainBody)

Introduction

Go Simple Mail is a simple and efficient package to send emails. It is well tested and documented.

Go Simple Mail can only send emails using an SMTP server. But the API is flexible and it is easy to implement other methods for sending emails using a local Postfix, an API, etc.

This package contains (and is based on) two packages by Joe Grasse:

  • https://github.com/joegrasse/mail (unmaintained since Jun 29, 2018), and
  • https://github.com/joegrasse/mime (unmaintained since Oct 1, 2015).

A lot of changes in Go Simple Mail were sent with not response.

Features

Go Simple Mail supports:

  • Multiple Attachments with path
  • Multiple Attachments in base64
  • Multiple Attachments from bytes (since v2.6.0)
  • Inline attachments from file, base64 and bytes (bytes since v2.6.0)
  • Multiple Recipients
  • Priority
  • Reply to
  • Set sender
  • Set from
  • Allow sending mail with different envelope from (since v2.7.0)
  • Embedded images
  • HTML and text templates
  • Automatic encoding of special characters
  • SSL/TLS and STARTTLS
  • Unencrypted connection (not recommended)
  • Sending multiple emails with the same SMTP connection (Keep Alive or Persistent Connection)
  • Timeout for connect to a SMTP Server
  • Timeout for send an email
  • Return Path
  • Alternative Email Body
  • CC and BCC
  • Add Custom Headers in Message
  • Send NOOP, RESET, QUIT and CLOSE to SMTP client
  • PLAIN, LOGIN and CRAM-MD5 Authentication (since v2.3.0)
  • AUTO Authentication (since v2.14.0)
  • Allow connect to SMTP without authentication (since v2.10.0)
  • Custom TLS Configuration (since v2.5.0)
  • Send a RFC822 formatted message (since v2.8.0)
  • Send from localhost (yes, Go standard SMTP package cannot do that because... WTF Google!)
  • Support text/calendar content type body (since v2.11.0)
  • Support add a List-Unsubscribe header (since v2.11.0)
  • Support to add a DKIM signarure (since v2.11.0)
  • Support to send using custom connection, ideal for proxy (since v2.15.0)
  • Support Delivery Status Notification (DSN) (since v2.16.0)
  • Support text/x-amp-html content type body (since v2.16.0)

Documentation

https://pkg.go.dev/github.com/xhit/go-simple-mail/v2?tab=doc

Note 1: by default duplicated recipients throws an error, from v2.13.0 you can use email.AllowDuplicateAddress = true to avoid the check.

Note 2: by default Bcc header is not set in email. From v2.14.0 you can use email.AddBccToHeader = true to add this.

Note 3: by default all addresses are validated against RFC5322. Setting email.UseProvidedAddress = true skips this validation, but requires you to ensure a valid address is sent.

Download

This package uses go modules.

$ go get github.com/xhit/go-simple-mail/v2

Usage

…

Send multiple emails in same connection

…

Send with custom connection

It's possible to use a custom connection with custom dieler, like a dialer that uses a proxy server, etc...

With this, these servers params are ignored: Host, Port. You have total control of the connection.

Example using a conn for proxy:

…

More examples

See example/example_test.go.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Gobulk-emailbulk-email-senderemailgo

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类包管理
定价开源

> 相关工具

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image