https://github.com/jordan-wright/email
Robust and flexible email library for Go
https://github.com/jordan-wright/email
Last synced: 7 months ago
JSON representation
Robust and flexible email library for Go
- Host: GitHub
- URL: https://github.com/jordan-wright/email
- Owner: jordan-wright
- License: mit
- Created: 2013-12-12T20:11:59.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2024-02-21T15:25:08.000Z (almost 2 years ago)
- Last Synced: 2025-04-24T08:34:49.088Z (7 months ago)
- Language: Go
- Homepage:
- Size: 195 KB
- Stars: 2,718
- Watchers: 58
- Forks: 323
- Open Issues: 55
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - jordan-wright/email
- awesome-ccamel - jordan-wright/email - Robust and flexible email library for Go (Go)
- go-awesome - jordan-wright/email
- awesome-go-cn - email - wright/email) (电子邮件 / 检索及分析资料库)
- go-awesome - jordan-wright/email
- awesome-go - email - Robust and flexible email library for Go - ★ 951 (Email)
- awesome-go-plus - email - A robust and flexible email library for Go.  (Email / Search and Analytic Databases)
- awesome-go - email - A robust and flexible email library for Go. (Email / Search and Analytic Databases)
- fucking-awesome-go - :octocat: email - A robust and flexible email library for Go. :star: 682 :fork_and_knife: 67 (Email / Advanced Console UIs)
- fucking-awesome-go - email - A robust and flexible email library for Go. (Email / Search and Analytic Databases)
- awesome-go - email - | - | - | (Email / Advanced Console UIs)
- awesome-go - email - A robust and flexible email library for Go. (Email / Search and Analytic Databases)
- awesome-go - email - A robust and flexible email library for Go. Stars:`2.8K`. (Email / Search and Analytic Databases)
- awesome-golang - email
- awesome-go - email - A robust and flexible email library for Go. - :arrow_down:127 - :star:701 (Email / Advanced Console UIs)
- awesome-go-with-stars - email - A robust and flexible email library for Go. (Email / Search and Analytic Databases)
- awesome-cobol - email - A robust and flexible email library for Cobol. (Email / Middlewares)
- awesome-go-cn - email - wright/email) (电子邮件 / 检索及分析资料库)
- awesome-go-cn - email
- awesome-go - email - A robust and flexible email library for Go. (Email / Search and Analytic Databases)
- awesome-go-extra - email - 12-12T20:11:59Z|2021-12-17T03:22:10Z| (Email / Advanced Console UIs)
- awesome-go - email - 用于Go的健壮而灵活的电子邮件库。 (<span id="电子邮件-email">电子邮件 Email</span> / <span id="高级控制台用户界面-advanced-console-uis">高级控制台用户界面 Advanced Console UIs</span>)
- awesome-go-cn - email
- awesome-go - email - A robust and flexible email library for Go. (Email / Advanced Console UIs)
- awesome-go - email - A robust and flexible email library for Go. (Email / Search and Analytic Databases)
- awesome-go - email - A robust and flexible email library for Go. (Email / Search and Analytic Databases)
- awesome-Char - email - A robust and flexible email library for Go. (Email / Advanced Console UIs)
- awesome-go - email - A robust and flexible email library for Go. (Email / Advanced Console UIs)
README
email
=====
[](https://travis-ci.org/jordan-wright/email) [](https://godoc.org/github.com/jordan-wright/email)
Robust and flexible email library for Go
### Email for humans
The ```email``` package is designed to be simple to use, but flexible enough so as not to be restrictive. The goal is to provide an *email interface for humans*.
The ```email``` package currently supports the following:
* From, To, Bcc, and Cc fields
* Email addresses in both "test@example.com" and "First Last <test@example.com>" format
* Text and HTML Message Body
* Attachments
* Read Receipts
* Custom headers
* More to come!
### Installation
```go get github.com/jordan-wright/email```
*Note: Version > 1 of this library requires Go v1.5 or above.*
*If you need compatibility with previous Go versions, you can use the previous package at gopkg.in/jordan-wright/email.v1*
### Examples
#### Sending email using Gmail
```go
e := email.NewEmail()
e.From = "Jordan Wright "
e.To = []string{"test@example.com"}
e.Bcc = []string{"test_bcc@example.com"}
e.Cc = []string{"test_cc@example.com"}
e.Subject = "Awesome Subject"
e.Text = []byte("Text Body is, of course, supported!")
e.HTML = []byte("
Fancy HTML is supported, too!
")
e.Send("smtp.gmail.com:587", smtp.PlainAuth("", "test@gmail.com", "password123", "smtp.gmail.com"))
```
#### Another Method for Creating an Email
You can also create an email directly by creating a struct as follows:
```go
e := &email.Email {
To: []string{"test@example.com"},
From: "Jordan Wright ",
Subject: "Awesome Subject",
Text: []byte("Text Body is, of course, supported!"),
HTML: []byte("
Fancy HTML is supported, too!
"),
Headers: textproto.MIMEHeader{},
}
```
#### Creating an Email From an io.Reader
You can also create an email from any type that implements the ```io.Reader``` interface by using ```email.NewEmailFromReader```.
#### Attaching a File
```go
e := NewEmail()
e.AttachFile("test.txt")
```
#### A Pool of Reusable Connections
```go
(var ch <-chan *email.Email)
p := email.NewPool(
"smtp.gmail.com:587",
4,
smtp.PlainAuth("", "test@gmail.com", "password123", "smtp.gmail.com"),
)
for i := 0; i < 4; i++ {
go func() {
for e := range ch {
p.Send(e, 10 * time.Second)
}
}()
}
```
### Documentation
[http://godoc.org/github.com/jordan-wright/email](http://godoc.org/github.com/jordan-wright/email)
### Other Sources
Sections inspired by the handy [gophermail](https://github.com/jpoehls/gophermail) project.
### Contributors
I'd like to thank all the [contributors and maintainers](https://github.com/jordan-wright/email/graphs/contributors) of this package.
A special thanks goes out to Jed Denlea [jeddenlea](https://github.com/jeddenlea) for his numerous contributions and optimizations.