修改第三方email包,pool修改为tls模式,否则腾讯企业邮箱无法发送
![]() |
3 سال پیش | |
---|---|---|
.github | 5 سال پیش | |
.gitignore | 5 سال پیش | |
.travis.yml | 6 سال پیش | |
LICENSE | 11 سال پیش | |
README.md | 6 سال پیش | |
email.go | 4 سال پیش | |
email_test.go | 4 سال پیش | |
go.mod | 3 سال پیش | |
pool.go | 3 سال پیش |
Robust and flexible email library for Go
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:
*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 test@gmail.com" 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("
#### 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 <test@gmail.com>",
Subject: "Awesome Subject",
Text: []byte("Text Body is, of course, supported!"),
HTML: []byte("<h1>Fancy HTML is supported, too!</h1>"),
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)
}
}()
} ```
http://godoc.org/github.com/jordan-wright/email
Sections inspired by the handy gophermail project.
I'd like to thank all the contributors and maintainers of this package.
A special thanks goes out to Jed Denlea jeddenlea for his numerous contributions and optimizations.