-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.go
71 lines (59 loc) · 1.38 KB
/
client.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package gomailer
import (
"context"
"errors"
)
type Implementation int
const (
Gomail = Implementation(iota)
Postmark
)
type Client interface {
// Send will send email
Send(msg *Message) error
// SendContext provide context to send function
SendContext(ctx context.Context, msg *Message) error
// SendAsync sends email asynchronously ignoring future error
SendAsync(msg *Message) error
// Close permanently close client connection
Close() error
}
type Message struct {
// From overrides global senderPool's email
From string
Attachments []*Attachment
SendTo []string
CC []string
BCC []string
Title string
Body string
// ContentType defaults to "text/html" if not set
ContentType string
}
type Attachment struct {
Filename string
Byte []byte
}
type Config struct {
Host string
Port int
// FromEmail configures the global senderPool's email
FromEmail string
Username string
Password string
// Postmark Settings
ServerToken string
AccountToken string
}
var ErrClosed = errors.New("connection has been closed")
// New email return email handler struct
func NewClient(impl Implementation, emailConfig *Config) (Client, error) {
switch impl {
case Gomail:
return newGomail(emailConfig), nil
case Postmark:
return newPostmark(emailConfig), nil
default:
return nil, errors.New("no email implementations found")
}
}