mailmerger

package module
v0.0.0-...-f44e3a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2022 License: MIT Imports: 8 Imported by: 2 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Mailmerger

Mailmerger, customize your email and send it to all recipients in the csv.

Usage example:


// errors are omitted for simplicity

var csvStr = `email,name,token
john@doe.com,john doe,token1
jean@doe.com,jean doe,token2
han@doe.com,han doe,token3
`

var bodyTmpl = `
	Selamat pagi {{ name | lower | title }}
	Berikut adalah token registrasi yang dapat dipakai {{ token }}
`

var subjectTmpl = `
	Token Registrasi {{ name | lower | title }}
`

defaultSubject := "Hay there!"
mailer := NewMailer(&MailerConfig{
	SenderEmail:     "test@email.com",
	DefaultSubject:  "Hai there",
	Concurrency:     2,
	Transporter:     mailTransporter,
	CsvSrc:          strings.NewReader(csvStr),
	BodyTemplate:    strings.NewReader(bodyTmpl),
	SubjectTemplate: strings.NewReader(subjectTmpl),
})
mailer.ParseCsv(strings.NewReader(csvStr))
mailer.ParseBodyTemplate(strings.NewReader(bodyTmpl))
mailer.ParseSubjectTemplate(strings.NewReader(subjectTmpl))

err = mailer.SendAll(ctx)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterFilter

func RegisterFilter(name string, fn pongo2.FilterFunction) error

RegisterFilter expose pongo2.RegisterFilter

Types

type CSV

type CSV struct {
	// contains filtered or unexported fields
}

CSV a csv parser

func (*CSV) IsHeader

func (c *CSV) IsHeader(header string) bool

IsHeader check if the header is exists

func (*CSV) Parse

func (c *CSV) Parse(rd io.Reader) (err error)

func (*CSV) Rows

func (c *CSV) Rows() []Row

type Mailer

type Mailer struct {
	*MailerConfig
	// contains filtered or unexported fields
}

func NewMailer

func NewMailer(cfg *MailerConfig) *Mailer

func (*Mailer) Parse

func (m *Mailer) Parse() (err error)

Parse parse csv & templates

func (*Mailer) SendAll

func (m *Mailer) SendAll(ctx context.Context) (err error)

SendAll send email to all recipient from csv

type MailerConfig

type MailerConfig struct {
	SenderEmail string
	// DefaultSubject use when the subject template is empty
	DefaultSubject  string
	CsvSrc          io.Reader
	BodyTemplate    io.Reader
	SubjectTemplate io.Reader
	Concurrency     uint
	Transporter     Transporter
}

type Row

type Row struct {
	// contains filtered or unexported fields
}

Row represent a Row in csv

func (Row) GetCell

func (r Row) GetCell(key string) (record string)

GetCell get a cell value by a header key

func (Row) Map

func (r Row) Map() map[string]interface{}

Map transform row into a map

type Transporter

type Transporter interface {
	Send(ctx context.Context, subject, from, to string, body []byte) error
}

Directories

Path Synopsis
cmd
mailmerger command
pkg
tests
mock_mailmerger
Package mock_mailmerger is a generated GoMock package.
Package mock_mailmerger is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址