Skip to content
forked from shmsr/smtppool

High throughput Go SMTP pool library with graceful handling of idle timeouts, errors, and retries.

License

Notifications You must be signed in to change notification settings

TomBoss/smtppool

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Usage

package main

import (
	"fmt"
	"log"

	"github.com/knadh/smtppool"
)

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,
	})
	if err != nil {
		log.Fatalf("error creating pool: %v", err)
	}

	e:= 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.

About

High throughput Go SMTP pool library with graceful handling of idle timeouts, errors, and retries.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%