1
|
|
|
package pinpointemail |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
|
6
|
|
|
SDK "github.com/aws/aws-sdk-go-v2/service/pinpointemail" |
7
|
|
|
|
8
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors" |
9
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers" |
10
|
|
|
) |
11
|
|
|
|
12
|
|
|
// SendEmail executes `SendEmail` operation. |
13
|
|
|
func (svc *PinpointEmail) SendEmail(ctx context.Context, r SendEmailRequest) (*SendEmailResult, error) { |
14
|
|
|
out, err := svc.RawSendEmail(ctx, r.ToInput()) |
15
|
|
|
if err != nil { |
16
|
|
|
err = svc.errWrap(errors.ErrorData{ |
17
|
|
|
Err: err, |
18
|
|
|
AWSOperation: "SendEmail", |
19
|
|
|
}) |
20
|
|
|
svc.Errorf(err.Error()) |
|
|
|
|
21
|
|
|
return nil, err |
22
|
|
|
} |
23
|
|
|
return NewSendEmailResult(out), nil |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
// SendEmailRequest has parameters for `SendEmail` operation. |
27
|
|
|
type SendEmailRequest struct { |
28
|
|
|
To []string |
29
|
|
|
Cc []string |
30
|
|
|
Bcc []string |
31
|
|
|
From string |
32
|
|
|
|
33
|
|
|
// for text or html |
34
|
|
|
Body string |
35
|
|
|
BodyCharset string |
36
|
|
|
Subject string |
37
|
|
|
SubjectCharset string |
38
|
|
|
UseHTML bool |
39
|
|
|
|
40
|
|
|
// for template |
41
|
|
|
TemplateARN string |
42
|
|
|
TemplateData string |
43
|
|
|
|
44
|
|
|
// for raw |
45
|
|
|
RawMessageData []byte |
46
|
|
|
|
47
|
|
|
ConfigurationSetName string |
48
|
|
|
EmailTags []Tag |
49
|
|
|
FeedbackForwardingEmailAddress string |
50
|
|
|
ReplyToAddresses []string |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
func (r SendEmailRequest) ToInput() *SDK.SendEmailInput { |
|
|
|
|
54
|
|
|
in := &SDK.SendEmailInput{} |
55
|
|
|
switch { |
56
|
|
|
case len(r.To) != 0, |
57
|
|
|
len(r.Cc) != 0, |
58
|
|
|
len(r.Bcc) != 0: |
59
|
|
|
in.Destination = &SDK.Destination{ |
60
|
|
|
ToAddresses: r.To, |
61
|
|
|
CcAddresses: r.Cc, |
62
|
|
|
BccAddresses: r.Bcc, |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
if r.From != "" { |
66
|
|
|
in.FromEmailAddress = pointers.String(r.From) |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if len(r.RawMessageData) != 0 { |
70
|
|
|
in.Content = &SDK.EmailContent{ |
71
|
|
|
Raw: &SDK.RawMessage{ |
72
|
|
|
Data: r.RawMessageData, |
73
|
|
|
}, |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
switch { |
78
|
|
|
case r.Subject != "", |
79
|
|
|
r.Body != "": |
80
|
|
|
if in.Content == nil { |
81
|
|
|
in.Content = &SDK.EmailContent{} |
82
|
|
|
} |
83
|
|
|
in.Content.Simple = &SDK.Message{} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if r.Subject != "" { |
87
|
|
|
content := SDK.Content{ |
88
|
|
|
Data: pointers.String(r.Subject), |
89
|
|
|
} |
90
|
|
|
if r.SubjectCharset != "" { |
91
|
|
|
content.Charset = pointers.String(r.SubjectCharset) |
92
|
|
|
} |
93
|
|
|
in.Content.Simple.Subject = &content |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if r.Body != "" { |
97
|
|
|
content := SDK.Content{ |
98
|
|
|
Data: pointers.String(r.Body), |
99
|
|
|
} |
100
|
|
|
if r.BodyCharset != "" { |
101
|
|
|
content.Charset = pointers.String(r.BodyCharset) |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
body := SDK.Body{} |
105
|
|
|
switch { |
106
|
|
|
case r.UseHTML: |
107
|
|
|
body.Html = &content |
108
|
|
|
default: |
109
|
|
|
body.Text = &content |
110
|
|
|
} |
111
|
|
|
in.Content.Simple.Body = &body |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if r.TemplateARN != "" { |
115
|
|
|
template := SDK.Template{ |
116
|
|
|
TemplateArn: pointers.String(r.TemplateARN), |
117
|
|
|
} |
118
|
|
|
if r.TemplateData != "" { |
119
|
|
|
template.TemplateData = pointers.String(r.TemplateData) |
120
|
|
|
} |
121
|
|
|
in.Content.Template = &template |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
if r.ConfigurationSetName != "" { |
125
|
|
|
in.ConfigurationSetName = pointers.String(r.ConfigurationSetName) |
126
|
|
|
} |
127
|
|
|
if len(r.EmailTags) != 0 { |
128
|
|
|
list := make([]SDK.MessageTag, len(r.EmailTags)) |
129
|
|
|
for i, v := range r.EmailTags { |
130
|
|
|
list[i] = v.ToEmailTag() |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
if r.FeedbackForwardingEmailAddress != "" { |
134
|
|
|
in.FeedbackForwardingEmailAddress = pointers.String(r.FeedbackForwardingEmailAddress) |
135
|
|
|
} |
136
|
|
|
in.ReplyToAddresses = r.ReplyToAddresses |
137
|
|
|
return in |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
type SendEmailResult struct { |
|
|
|
|
141
|
|
|
MessageID string |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
func NewSendEmailResult(o *SDK.SendEmailResponse) *SendEmailResult { |
|
|
|
|
145
|
|
|
result := &SendEmailResult{} |
146
|
|
|
if o == nil { |
147
|
|
|
return result |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
if o.MessageId != nil { |
151
|
|
|
result.MessageID = *o.MessageId |
152
|
|
|
} |
153
|
|
|
return result |
154
|
|
|
} |
155
|
|
|
|