用于发送电子邮件的 Golang 包。支持保持活动连接、TLS 和 SSL。适用于批量 SMTP。
The best way to send emails in Go with SMTP Keep Alive and Timeout for Connect and Send.
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)
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:
A lot of changes in Go Simple Mail were sent with not response.
Go Simple Mail supports:
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.
This package uses go modules.
$ go get github.com/xhit/go-simple-mail/v2
…
…
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:
…
暂无开放 Issues,或尚未同步最近议题。