-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmail.go
158 lines (119 loc) · 4.32 KB
/
mail.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package zeptomail
import (
"fmt"
"net/http"
)
// SendHTMLEmail sends a HTML email
func (c *Client) SendHTMLEmail(req SendHTMLEmailReq) (*SendHTMLEmailRes, error) {
url := "email"
if err := validate.Struct(&req); err != nil {
return nil, err
}
var response SendHTMLEmailRes
if err := c.newRequest(http.MethodPost, url, req, &response); err != nil {
return nil, err
}
return &response, nil
}
// SendTemplatedEmail sends a templated email
func (c *Client) SendTemplatedEmail(req SendTemplatedEmailReq) (*SendTemplatedEmailRes, error) {
url := "email/template"
if err := validate.Struct(&req); err != nil {
return nil, err
}
var response SendTemplatedEmailRes
if err := c.newRequest(http.MethodPost, url, req, &response); err != nil {
return nil, err
}
return &response, nil
}
// SendBatchTemplatedEmail sends a batch templated email
func (c *Client) SendBatchTemplatedEmail(req SendBatchTemplatedEmailReq) (*SendTemplatedEmailRes, error) {
url := "email/template/batch"
if err := validate.Struct(&req); err != nil {
return nil, err
}
var response SendTemplatedEmailRes
if err := c.newRequest(http.MethodPost, url, req, &response); err != nil {
return nil, err
}
return &response, nil
}
// AddEmailTemplate is used to add an email template.
func (c *Client) AddEmailTemplate(req AddEmailTemplateReq) (*AddEmailTemplateRes, error) {
url := fmt.Sprintf("mailagents/%s/templates", req.MailagentAlias)
if err := validate.Struct(&req); err != nil {
return nil, err
}
var response AddEmailTemplateRes
if err := c.newRequest(http.MethodPost, url, req, &response); err != nil {
return nil, err
}
return &response, nil
}
// UpdateEmailTemplate is used to update an email template.
func (c *Client) UpdateEmailTemplate(req UpdateEmailTemplateReq) (*AddEmailTemplateRes, error) {
url := fmt.Sprintf("mailagents/%s/templates/%s", req.MailagentAlias, req.TemplateKey)
if err := validate.Struct(&req); err != nil {
return nil, err
}
var response AddEmailTemplateRes
if err := c.newRequest(http.MethodPut, url, req, &response); err != nil {
return nil, err
}
return &response, nil
}
// GetEmailTemplate is used to fetch a particular email template.
func (c *Client) GetEmailTemplate(MailAgentAlias, TemplateKey string) (*GetEmailTemplateRes, error) {
url := fmt.Sprintf("mailagents/%s/templates/%s", MailAgentAlias, TemplateKey)
var response GetEmailTemplateRes
if err := c.newRequest(http.MethodGet, url, nil, &response); err != nil {
return nil, err
}
return &response, nil
}
// DeleteEmailTemplate is used to delete a template using template key.
func (c *Client) DeleteEmailTemplate(MailAgentAlias, TemplateKey string) (*interface{}, error) {
url := fmt.Sprintf("mailagents/%s/templates/%s", MailAgentAlias, TemplateKey)
var response interface{}
if err := c.newRequest(http.MethodDelete, url, nil, &response); err != nil {
return nil, err
}
return &response, nil
}
// SendBatchHTMLEmail The API is used to send a batch of transactional HTML emails.
func (c *Client) SendBatchHTMLEmail(req SendBatchHTMLEmailReq) (res *SendBatchHTMLEmailRes, err error) {
url := "email/batch"
if err := validate.Struct(&req); err != nil {
return nil, err
}
var response SendBatchHTMLEmailRes
if err := c.newRequest(http.MethodPost, url, req, &response); err != nil {
return nil, err
}
return &response, nil
}
// FileCacheUploadAPI The API is used to upload files to File Cache
func (c *Client) FileCacheUploadAPI(req FileCacheUploadAPIReq) (res *FileCacheUploadAPIRes, err error) {
url := fmt.Sprintf("%sfiles?name=%s", c.BaseUrl, req.FileName)
if err := validate.Struct(&req); err != nil {
return nil, err
}
var response FileCacheUploadAPIRes
if err := c.newRequest(http.MethodPost, url, req, &response); err != nil {
return nil, err
}
return &response, nil
}
// ListEmailTemplates You can use this API to list the required number of email templates in your ZeptoMail account.
func (c *Client) ListEmailTemplates(MailAgentAlias string, Offset, limit int) (req *ListEmailTemplatesRes, err error) {
url := fmt.Sprintf("mailagents/%s/templates?offset=%d&limit=%d", MailAgentAlias, Offset, limit)
if err := validate.Struct(&req); err != nil {
return nil, err
}
var response ListEmailTemplatesRes
if err := c.newRequest(http.MethodGet, url, nil, &response); err != nil {
return nil, err
}
return &response, nil
}