forked from pocketbase/pocketbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailer.go
38 lines (32 loc) · 896 Bytes
/
mailer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package tests
import (
"io"
"net/mail"
"github.com/pocketbase/pocketbase/tools/mailer"
)
var _ mailer.Mailer = (*TestMailer)(nil)
// TestMailer is a mock `mailer.Mailer` implementation.
type TestMailer struct {
TotalSend int
LastFromAddress mail.Address
LastToAddress mail.Address
LastHtmlSubject string
LastHtmlBody string
}
// Reset clears any previously test collected data.
func (m *TestMailer) Reset() {
m.TotalSend = 0
m.LastFromAddress = mail.Address{}
m.LastToAddress = mail.Address{}
m.LastHtmlSubject = ""
m.LastHtmlBody = ""
}
// Send implements `mailer.Mailer` interface.
func (m *TestMailer) Send(fromEmail mail.Address, toEmail mail.Address, subject string, html string, attachments map[string]io.Reader) error {
m.LastFromAddress = fromEmail
m.LastToAddress = toEmail
m.LastHtmlSubject = subject
m.LastHtmlBody = html
m.TotalSend++
return nil
}