|
1
|
|
|
package ses |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"context" |
|
5
|
|
|
|
|
6
|
|
|
SDK "github.com/aws/aws-sdk-go-v2/service/ses" |
|
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 *SES) 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
|
|
|
Destination Destination |
|
29
|
|
|
Source string |
|
30
|
|
|
|
|
31
|
|
|
Subject string |
|
32
|
|
|
SubjectCharset string // optional |
|
33
|
|
|
|
|
34
|
|
|
// Either HTMLBody or TextBody is required |
|
35
|
|
|
HTMLBody string |
|
36
|
|
|
HTMLCharset string |
|
37
|
|
|
TextBody string |
|
38
|
|
|
TextCharset string |
|
39
|
|
|
|
|
40
|
|
|
// optional |
|
41
|
|
|
ConfigurationSetName string |
|
42
|
|
|
ReplyToAddresses []string |
|
43
|
|
|
ReturnPath string |
|
44
|
|
|
ReturnPathARN string |
|
45
|
|
|
SourceARN string |
|
46
|
|
|
Tags []MessageTag |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
func (r SendEmailRequest) ToInput() *SDK.SendEmailInput { |
|
|
|
|
|
|
50
|
|
|
in := &SDK.SendEmailInput{ |
|
51
|
|
|
Message: &SDK.Message{}, |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
in.Destination = r.Destination.ToSDK() |
|
55
|
|
|
|
|
56
|
|
|
if r.Source != "" { |
|
57
|
|
|
in.Source = pointers.String(r.Source) |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if r.Subject != "" { |
|
61
|
|
|
content := SDK.Content{ |
|
62
|
|
|
Data: pointers.String(r.Subject), |
|
63
|
|
|
} |
|
64
|
|
|
if r.SubjectCharset != "" { |
|
65
|
|
|
content.Charset = pointers.String(r.SubjectCharset) |
|
66
|
|
|
} |
|
67
|
|
|
in.Message.Subject = &content |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if r.HTMLBody != "" || r.TextBody != "" { |
|
71
|
|
|
body := SDK.Body{} |
|
72
|
|
|
if r.HTMLBody != "" { |
|
73
|
|
|
content := SDK.Content{} |
|
74
|
|
|
content.Data = pointers.String(r.HTMLBody) |
|
75
|
|
|
if r.HTMLCharset != "" { |
|
76
|
|
|
content.Charset = pointers.String(r.HTMLCharset) |
|
77
|
|
|
} |
|
78
|
|
|
body.Html = &content |
|
79
|
|
|
} |
|
80
|
|
|
if r.TextBody != "" { |
|
81
|
|
|
content := SDK.Content{} |
|
82
|
|
|
content.Data = pointers.String(r.TextBody) |
|
83
|
|
|
if r.TextCharset != "" { |
|
84
|
|
|
content.Charset = pointers.String(r.TextCharset) |
|
85
|
|
|
} |
|
86
|
|
|
body.Text = &content |
|
87
|
|
|
} |
|
88
|
|
|
in.Message.Body = &body |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if r.ConfigurationSetName != "" { |
|
92
|
|
|
in.ConfigurationSetName = pointers.String(r.ConfigurationSetName) |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
in.ReplyToAddresses = r.ReplyToAddresses |
|
96
|
|
|
|
|
97
|
|
|
if r.ReturnPath != "" { |
|
98
|
|
|
in.ReturnPath = pointers.String(r.ReturnPath) |
|
99
|
|
|
} |
|
100
|
|
|
if r.ReturnPathARN != "" { |
|
101
|
|
|
in.ReturnPathArn = pointers.String(r.ReturnPathARN) |
|
102
|
|
|
} |
|
103
|
|
|
if r.SourceARN != "" { |
|
104
|
|
|
in.SourceArn = pointers.String(r.SourceARN) |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
if len(r.Tags) != 0 { |
|
108
|
|
|
list := make([]SDK.MessageTag, len(r.Tags)) |
|
109
|
|
|
for i, v := range r.Tags { |
|
110
|
|
|
list[i] = v.ToSDK() |
|
111
|
|
|
} |
|
112
|
|
|
in.Tags = list |
|
113
|
|
|
} |
|
114
|
|
|
return in |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
type SendEmailResult struct { |
|
|
|
|
|
|
118
|
|
|
MessageID string |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
func NewSendEmailResult(o *SDK.SendEmailResponse) *SendEmailResult { |
|
|
|
|
|
|
122
|
|
|
result := &SendEmailResult{} |
|
123
|
|
|
if o == nil { |
|
124
|
|
|
return result |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
if o.MessageId != nil { |
|
128
|
|
|
result.MessageID = *o.MessageId |
|
129
|
|
|
} |
|
130
|
|
|
return result |
|
131
|
|
|
} |
|
132
|
|
|
|