-
Notifications
You must be signed in to change notification settings - Fork 32
/
mailjet_resources.go
280 lines (242 loc) · 8.54 KB
/
mailjet_resources.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package mailjet
import (
"fmt"
"net/http"
"net/textproto"
"sync"
"encoding/json"
)
/*
** API structures
*/
// Client bundles data needed by a large number
// of methods in order to interact with the Mailjet API.
type Client struct {
apiBase string
httpClient HTTPClientInterface
smtpClient SMTPClientInterface
sync.Mutex
}
// Request bundles data needed to build the URL.
type Request struct {
Resource string
ID int64
AltID string
Action string
ActionID int64
}
// DataRequest bundles data needed to build the DATA URL.
type DataRequest struct {
SourceType string
SourceTypeID int64
DataType string
MimeType string
DataTypeID int64
LastID bool
}
// FullRequest is the same as a Request but with a payload.
type FullRequest struct {
Info *Request
Payload interface{}
}
// FullDataRequest is the same as a DataRequest but with a payload.
type FullDataRequest struct {
Info *DataRequest
Payload interface{}
}
// RequestOptions are functional options that modify the specified request.
type RequestOptions func(*http.Request)
// RequestResult is the JSON result sent by the API.
type RequestResult struct {
Count int
Data interface{}
Total int
}
// RequestError is the error returned by the API.
type RequestError struct {
ErrorInfo string
ErrorMessage string
StatusCode int
}
func (e RequestError) Error() string {
return fmt.Sprintf("Unexpected server response code: %d: %s (%s)", e.StatusCode, e.ErrorMessage, e.ErrorInfo)
}
// RequestErrorV31 is the error returned by the API.
type RequestErrorV31 struct {
ErrorInfo string
ErrorMessage string
StatusCode int
ErrorIdentifier string
}
/*
** Send API structures
*/
// InfoSendMail bundles data used by the Send API.
type InfoSendMail struct {
FromEmail string
FromName string
Sender string `json:",omitempty"`
Recipients []Recipient `json:",omitempty"`
To string `json:",omitempty"`
Cc string `json:",omitempty"`
Bcc string `json:",omitempty"`
Subject string
TextPart string `json:"Text-part,omitempty"`
HTMLPart string `json:"Html-part,omitempty"`
Attachments []Attachment `json:",omitempty"`
InlineAttachments []Attachment `json:"Inline_attachments,omitempty"`
MjPrio int `json:"Mj-prio,omitempty"`
MjCampaign string `json:"Mj-campaign,omitempty"`
MjDeduplicateCampaign bool `json:"Mj-deduplicatecampaign,omitempty"`
MjCustomID string `json:"Mj-CustomID,omitempty"`
MjTemplateID string `json:"Mj-TemplateID,omitempty"`
MjTemplateErrorReporting string `json:"MJ-TemplateErrorReporting,omitempty"`
MjTemplateLanguage string `json:"Mj-TemplateLanguage,omitempty"`
MjTemplateErrorDeliver string `json:"MJ-TemplateErrorDeliver,omitempty"`
MjEventPayLoad string `json:"Mj-EventPayLoad,omitempty"`
Headers map[string]string `json:",omitempty"`
Vars interface{} `json:",omitempty"`
Messages []InfoSendMail `json:",omitempty"`
}
// Recipient bundles data on the target of the mail.
type Recipient struct {
Email string
Name string
Vars interface{} `json:",omitempty"`
}
// Attachment bundles data on the file attached to the mail.
type Attachment struct {
ContentType string `json:"Content-Type"`
Content string
Filename string
}
// SentResult is the JSON result sent by the Send API.
type SentResult struct {
Sent []struct {
Email string
MessageID int64
}
}
/*
** SMTP mail sending structures
*/
// InfoSMTP contains mandatory informations to send a mail via SMTP.
type InfoSMTP struct {
From string
Recipients []string
Header textproto.MIMEHeader
Content []byte
}
/*
** Send API v3.1 structures
*/
// MessagesV31 definition
type MessagesV31 struct {
Info []InfoMessagesV31 `json:"Messages,omitempty"`
AdvanceErrorHandling bool `json:"AdvanceErrorHandling,omitempty"`
SandBoxMode bool `json:",omitempty"`
}
// InfoMessagesV31 represents the payload input taken by send API v3.1
type InfoMessagesV31 struct {
From *RecipientV31 `json:",omitempty"`
ReplyTo *RecipientV31 `json:",omitempty"`
Sender *RecipientV31 `json:",omitempty"`
To *RecipientsV31 `json:",omitempty"`
Cc *RecipientsV31 `json:",omitempty"`
Bcc *RecipientsV31 `json:",omitempty"`
Attachments *AttachmentsV31 `json:",omitempty"`
InlinedAttachments *InlinedAttachmentsV31 `json:",omitempty"`
Subject string `json:",omitempty"`
TextPart string `json:",omitempty"`
HTMLPart string `json:",omitempty"`
Priority int `json:",omitempty"`
CustomCampaign string `json:",omitempty"`
StatisticsContactsListID int `json:",omitempty"`
MonitoringCategory string `json:",omitempty"`
DeduplicateCampaign bool `json:",omitempty"`
TrackClicks string `json:",omitempty"`
TrackOpens string `json:",omitempty"`
CustomID string `json:",omitempty"`
Variables map[string]interface{} `json:",omitempty"`
EventPayload string `json:",omitempty"`
TemplateID int `json:",omitempty"`
TemplateLanguage bool `json:",omitempty"`
TemplateErrorReporting *RecipientV31 `json:",omitempty"`
TemplateErrorDeliver bool `json:",omitempty"`
Headers map[string]interface{} `json:",omitempty"`
}
// RecipientV31 struct handle users input
type RecipientV31 struct {
Email string `json:",omitempty"`
Name string `json:",omitempty"`
}
// RecipientsV31 is a collection of emails
type RecipientsV31 []RecipientV31
// AttachmentV31 struct represent a content attachment
type AttachmentV31 struct {
ContentType string `json:"ContentType,omitempty"`
Base64Content string `json:"Base64Content,omitempty"`
Filename string `json:"Filename,omitempty"`
}
// AttachmentsV31 collection
type AttachmentsV31 []AttachmentV31
// InlinedAttachmentV31 struct represent the content of an inline attachement
type InlinedAttachmentV31 struct {
AttachmentV31 `json:",omitempty"`
ContentID string `json:"ContentID,omitempty"`
}
// InlinedAttachmentsV31 collection
type InlinedAttachmentsV31 []InlinedAttachmentV31
// ErrorInfoV31 struct
type ErrorInfoV31 struct {
Identifier string `json:"ErrorIdentifier,omitempty"`
Info string `json:"ErrorInfo"`
Message string `json:"ErrorMessage"`
StatusCode int `json:"StatusCode"`
}
func (err *ErrorInfoV31) Error() string {
raw, _ := json.Marshal(err)
return string(raw)
}
// APIErrorDetailsV31 contains the information details describing a specific error
type APIErrorDetailsV31 struct {
// Deprecated: ErrorClass is no longer populated. Use the ErrorCode to
// classify the issue.
ErrorClass string
ErrorCode string
ErrorIdentifier string
ErrorMessage string
ErrorRelatedTo []string
StatusCode int
}
// APIFeedbackErrorV31 struct is composed of an error definition and the payload associated
type APIFeedbackErrorV31 struct {
Errors []APIErrorDetailsV31
}
// APIFeedbackErrorsV31 defines the error when a validation error is being sent by the API
type APIFeedbackErrorsV31 struct {
Messages []APIFeedbackErrorV31
}
func (api *APIFeedbackErrorsV31) Error() string {
raw, _ := json.Marshal(api)
return string(raw)
}
// GeneratedMessageV31 contains info to retrieve a generated email
type GeneratedMessageV31 struct {
Email string
MessageUUID string
MessageID int64
MessageHref string
}
// ResultV31 bundles the results of a sent email
type ResultV31 struct {
Status string
CustomID string `json:",omitempty"`
To []GeneratedMessageV31
Cc []GeneratedMessageV31
Bcc []GeneratedMessageV31
}
// ResultsV31 bundles several results when several mails are sent
type ResultsV31 struct {
ResultsV31 []ResultV31 `json:"Messages"`
}