-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.go
54 lines (48 loc) · 1.35 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
package mailazy
type SendMailRequest struct {
Path string
Payload *SendMailPayload
}
type SendMailPayload struct {
To []string `json:"to"`
From string `json:"from"`
ReplyTo string `json:"reply_to"`
CC []string `json:"cc"`
BCC []string `json:"bcc"`
Subject string `json:"subject,omitempty"`
Content []SendMailPayloadContent `json:"content,omitempty"`
}
type SendMailPayloadContent struct {
Type string `json:"type"`
Value string `json:"value"`
}
func NewSendMailRequest(to, from, subject, textContent, htmlContent string) *SendMailRequest {
return &SendMailRequest{
Path: DefaultVersion + "/" + SendMailPath,
Payload: &SendMailPayload{
To: []string{to},
From: from,
Subject: subject,
Content: []SendMailPayloadContent{{
Type: PlainTextContentType,
Value: textContent,
}, {
Type: HtmlContentType,
Value: htmlContent,
}},
},
}
}
func NewSendMailRequestWithParams(to, from, subject, textContent, htmlContent string, replyTo *string, cc, bcc []string) *SendMailRequest {
r := NewSendMailRequest(to, from, subject, textContent, htmlContent)
if replyTo != nil {
r.Payload.ReplyTo = *replyTo
}
if len(cc) > 0 {
r.Payload.CC = cc
}
if len(bcc) > 0 {
r.Payload.BCC = bcc
}
return r
}