Go to file
Kailash Nadh 6f93552458 RSET connection every time before re-using in the pool.
Ref:
https://github.com/knadh/listmonk/issues/1629
https://github.com/knadh/listmonk/issues/1530
https://github.com/knadh/listmonk/issues/1192
https://github.com/knadh/listmonk/issues/300
2023-12-23 12:05:52 +05:30
LICENSE First commit 2020-05-10 23:38:57 +05:30
README.md Fix typo 2021-02-20 11:49:48 +05:30
email.go Fix parsing attachments in NewEmailFromReader. 2022-03-15 10:23:14 +05:30
email_test.go Implements "multipart related" attachments based 2020-12-07 18:46:05 +01:00
go.mod First commit 2020-05-10 23:38:57 +05:30
pool.go RSET connection every time before re-using in the pool. 2023-12-23 12:05:52 +05:30

README.md

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 <john@example.com>",
		To:      []string{"doe@example.com"},

		// Optional.
		Bcc:     []string{"doebcc@example.com"},
		Cc:      []string{"doecc@example.com"},

		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.