Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

go-simple-mail

> 包管理
Open source

Golang package for send email. Support keep alive connection, TLS and SSL. Easy for bulk SMTP.

696 stars0 likes5 views
WebsiteGitHub

About

Golang package for send email. Support keep alive connection, TLS and SSL. Easy for bulk 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:

diff
  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.

bash
$ 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 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Gobulk-emailbulk-email-senderemailgo

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category包管理
PricingOpen source

> Related tools

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