# README
smtppool
smtppool is a Go library that creates a pool of reusable SMTP connections for high throughput e-mailing. It gracefully handles idle connections, timeouts, and retries. The e-mail formatting, parsing, and preparation code is forked from jordan-wright/email.
Install
go get github.com/knadh/smtppool/v2
Usage
package main
import (
"log"
"time"
"github.com/knadh/smtppool/v2"
)
func main() {
// Try https://github.com/mailhog/MailHog for running a local dummy SMTP server.
// Create a new pool.
pool, err := smtppool.New(smtppool.Opt{
Host: "localhost",
Port: 1025,
MaxConns: 10,
IdleTimeout: time.Second * 10,
PoolWaitTimeout: time.Second * 3,
SSL: smtppool.SSLNone
})
if err != nil {
log.Fatalf("error creating pool: %v", err)
}
e:= smtppool.Email{
From: "John Doe <[email protected]>",
To: []string{"[email protected]"},
// Optional.
Bcc: []string{"[email protected]"},
Cc: []string{"[email protected]"},
Subject: "Hello, World",
Text: []byte("This is a test e-mail"),
HTML: []byte("<strong>This is a test e-mail</strong>"),
}
// Add attachments.
if _, err := e.AttachFile("test.txt"); err != nil {
log.Fatalf("error attaching file: %v", err)
}
if err := pool.Send(e); err != nil {
log.Fatalf("error sending e-mail: %v", err)
}
}
Licensed under the MIT license.
# Functions
New initializes and returns a new SMTP Pool.
NewEmailFromReader reads a stream of bytes from an io.Reader, r, and returns an email struct containing the parsed data.
# Constants
Global constants.
Global constants.
Global constants.
Global constants.
Global constants.
Global constants.
SMTP headers and fields.
SMTP headers and fields.
SMTP headers and fields.
SMTP headers and fields.
SMTP headers and fields.
SMTP headers and fields.
SMTP headers and fields.
SMTP headers and fields.
SMTP headers and fields.
SMTP headers and fields.
SMTP headers and fields.
SMTP headers and fields.
SMTP headers and fields.
MaxLineLength is the maximum line length per RFC 2045.
SSLNone specifies a plain unencrypted connection.
SSLSTARTTLS specifies a non-TLS connection that then upgrades to STARTTLS.
SSLTLS specifies an SSL (TLS) connection without the STARTTLS extension.
# Variables
ErrMissingBoundary is returned when there is no boundary given for a multipart entity.
ErrMissingContentType is returned when there is no "Content-Type" header for a MIME entity.
ErrPoolClosed is thrown when a closed Pool is used.
# Structs
Attachment is a struct representing an email attachment.
Email represents an e-mail message.
LoginAuth is the SMTP "LOGIN" type implementation for smtp.Auth.
Opt represents SMTP pool options.
Pool represents an SMTP connection pool.
# Type aliases
SSLType is the type of SSL connection to use.