email sending library
![Coverage Status](https://coveralls.io/repos/github/go-pkgz/email/badge.svg?branch=master)
The library is a wrapper around the stdlib net/smtp
simplifying email sending. It supports authentication, SSL/TLS,
user-specified SMTP servers, content-type, charset, multiple recipients and more.
Usage example:
client := email.NewSender("localhost", email.ContentType("text/html"), email.Auth("user", "pass"))
err := client.Send("<html>some content, foo bar</html>",
email.Params{From: "me@example.com", To: []string{"to@example.com"}, Subject: "Hello world!"})
options
NewSender
accepts a number of options to configure the client:
Port
: SMTP port (default: 25)
TLS
: Use TLS SMTP (default: false)
Auth(user, password)
: Username and password for SMTP authentication (default: empty, no authentication)
ContentType
: Content type for the email (default: "text/plain")
Charset
: Charset for the email (default: "utf-8")
TimeOut
: Timeout for the SMTP connection (default: 30 seconds)
Log
: Logger to use (default: no logging)
SMTP
: Set custom smtp client (default: none)
Options should be passed to NewSender
after the mandatory first (host) parameter.
sending email
To send email user need to create a sender first and then use Send
method. The method accepts two parameters:
technical details
- Content-Transfer-Encoding set to
quoted-printable
- Custom SMTP client (
smtp.Client
from stdlib) can be set by user with SMTP
option. In this case it will be used instead of making a new smtp client internally.
- Logger can be set with
Log
option. It should implement email.Logger
interface with a single Logf(format string, args ...interface{})
method. By default, "no logging" internal logger is used. This interface is compatible with the go-pkgz/lgr
logger.
- The library has no external dependencies, except for testing. It uses the stdlib
net/smtp
package.
- SSL/TLS supported with
TLS
option. Pls note: this is not the same as STARTTLS
(not supported) which is usually on port 587 vs SSL/TLS on port 465.
limitations
This library is not intended to be used for sending emails with attachments or sending a lot of massive emails with
low latency requirements. The intended use case is sending simple messages, like alerts, notification and so on.
For example, sending alerts from a monitoring system, or for authentication-related emails, i.e. "password reset email",
"verification email", etc.