Emailing with optional limiter. It will send no more then limiterMax emails during limiterPeriod.
Install
go get github.com/kaibox-git/email
Usage
host := `localhost:25`
// Only 20 emails per 30 minutes. The rest is ignored.
// This is useful for notifications of errors, but has a limitation if emailing is too often.
// In this case send info to log file.
emailNumber := 20
period := 30 * time.Minute
emailSender, err := email.New(host, emailNumber, period)
if err != nil {
println(err.Error())
os.Exit(1)
}
// plain text with limiter
emailSender.Send(&email.Data{
ContentType: `plain`,
From: mail.Address{
Name: `Robot`,
Address: `[email protected]`,
},
To: []mail.Address{
{
Name: `Test address`,
Address: `[email protected]`,
},
},
Subject: `test subject`,
Body: `test message`,
WithLimiter: true,
})
// html body for 2 addresses with no limiter
emailSender.Send(&email.Data{
ContentType: `html`,
From: mail.Address{
Name: `Robot`,
Address: `[email protected]`,
},
To: []mail.Address{
{
Name: `Test address`,
Address: `[email protected]`,
},
{
Name: `Test address 2`,
Address: `[email protected]`,
},
},
Subject: `test subject`,
Body: `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Emailing HTML format</title>
</head>
<body>
<h1>Test HTML format</h1>
<p>This is a test body.</p>
</body>
</html>`,
WithLimiter: false,
})