-
Notifications
You must be signed in to change notification settings - Fork 623
/
api_op_SendEmail.go
253 lines (210 loc) · 7.63 KB
/
api_op_SendEmail.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
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
package pinpointemail
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/internal/awsutil"
"github.com/aws/aws-sdk-go-v2/private/protocol"
)
// A request to send an email message.
type SendEmailInput struct {
_ struct{} `type:"structure"`
// The name of the configuration set that you want to use when sending the email.
ConfigurationSetName *string `type:"string"`
// An object that contains the body of the message. You can send either a Simple
// message or a Raw message.
//
// Content is a required field
Content *EmailContent `type:"structure" required:"true"`
// An object that contains the recipients of the email message.
//
// Destination is a required field
Destination *Destination `type:"structure" required:"true"`
// A list of tags, in the form of name/value pairs, to apply to an email that
// you send using the SendEmail operation. Tags correspond to characteristics
// of the email that you define, so that you can publish email sending events.
EmailTags []MessageTag `type:"list"`
// The address that Amazon Pinpoint should send bounce and complaint notifications
// to.
FeedbackForwardingEmailAddress *string `type:"string"`
// The email address that you want to use as the "From" address for the email.
// The address that you specify has to be verified.
FromEmailAddress *string `type:"string"`
// The "Reply-to" email addresses for the message. When the recipient replies
// to the message, each Reply-to address receives the reply.
ReplyToAddresses []string `type:"list"`
}
// String returns the string representation
func (s SendEmailInput) String() string {
return awsutil.Prettify(s)
}
// Validate inspects the fields of the type to determine if they are valid.
func (s *SendEmailInput) Validate() error {
invalidParams := aws.ErrInvalidParams{Context: "SendEmailInput"}
if s.Content == nil {
invalidParams.Add(aws.NewErrParamRequired("Content"))
}
if s.Destination == nil {
invalidParams.Add(aws.NewErrParamRequired("Destination"))
}
if s.Content != nil {
if err := s.Content.Validate(); err != nil {
invalidParams.AddNested("Content", err.(aws.ErrInvalidParams))
}
}
if s.EmailTags != nil {
for i, v := range s.EmailTags {
if err := v.Validate(); err != nil {
invalidParams.AddNested(fmt.Sprintf("%s[%v]", "EmailTags", i), err.(aws.ErrInvalidParams))
}
}
}
if invalidParams.Len() > 0 {
return invalidParams
}
return nil
}
// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s SendEmailInput) MarshalFields(e protocol.FieldEncoder) error {
e.SetValue(protocol.HeaderTarget, "Content-Type", protocol.StringValue("application/json"), protocol.Metadata{})
if s.ConfigurationSetName != nil {
v := *s.ConfigurationSetName
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "ConfigurationSetName", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.Content != nil {
v := s.Content
metadata := protocol.Metadata{}
e.SetFields(protocol.BodyTarget, "Content", v, metadata)
}
if s.Destination != nil {
v := s.Destination
metadata := protocol.Metadata{}
e.SetFields(protocol.BodyTarget, "Destination", v, metadata)
}
if s.EmailTags != nil {
v := s.EmailTags
metadata := protocol.Metadata{}
ls0 := e.List(protocol.BodyTarget, "EmailTags", metadata)
ls0.Start()
for _, v1 := range v {
ls0.ListAddFields(v1)
}
ls0.End()
}
if s.FeedbackForwardingEmailAddress != nil {
v := *s.FeedbackForwardingEmailAddress
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "FeedbackForwardingEmailAddress", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.FromEmailAddress != nil {
v := *s.FromEmailAddress
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "FromEmailAddress", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
if s.ReplyToAddresses != nil {
v := s.ReplyToAddresses
metadata := protocol.Metadata{}
ls0 := e.List(protocol.BodyTarget, "ReplyToAddresses", metadata)
ls0.Start()
for _, v1 := range v {
ls0.ListAddValue(protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v1)})
}
ls0.End()
}
return nil
}
// A unique message ID that you receive when Amazon Pinpoint accepts an email
// for sending.
type SendEmailOutput struct {
_ struct{} `type:"structure"`
// A unique identifier for the message that is generated when Amazon Pinpoint
// accepts the message.
//
// It is possible for Amazon Pinpoint to accept a message without sending it.
// This can happen when the message you're trying to send has an attachment
// doesn't pass a virus check, or when you send a templated email that contains
// invalid personalization content, for example.
MessageId *string `type:"string"`
}
// String returns the string representation
func (s SendEmailOutput) String() string {
return awsutil.Prettify(s)
}
// MarshalFields encodes the AWS API shape using the passed in protocol encoder.
func (s SendEmailOutput) MarshalFields(e protocol.FieldEncoder) error {
if s.MessageId != nil {
v := *s.MessageId
metadata := protocol.Metadata{}
e.SetValue(protocol.BodyTarget, "MessageId", protocol.QuotedValue{ValueMarshaler: protocol.StringValue(v)}, metadata)
}
return nil
}
const opSendEmail = "SendEmail"
// SendEmailRequest returns a request value for making API operation for
// Amazon Pinpoint Email Service.
//
// Sends an email message. You can use the Amazon Pinpoint Email API to send
// two types of messages:
//
// * Simple – A standard email message. When you create this type of message,
// you specify the sender, the recipient, and the message body, and Amazon
// Pinpoint assembles the message for you.
//
// * Raw – A raw, MIME-formatted email message. When you send this type
// of email, you have to specify all of the message headers, as well as the
// message body. You can use this message type to send messages that contain
// attachments. The message that you specify has to be a valid MIME message.
//
// // Example sending a request using SendEmailRequest.
// req := client.SendEmailRequest(params)
// resp, err := req.Send(context.TODO())
// if err == nil {
// fmt.Println(resp)
// }
//
// Please also see https://docs.aws.amazon.com/goto/WebAPI/pinpoint-email-2018-07-26/SendEmail
func (c *Client) SendEmailRequest(input *SendEmailInput) SendEmailRequest {
op := &aws.Operation{
Name: opSendEmail,
HTTPMethod: "POST",
HTTPPath: "/v1/email/outbound-emails",
}
if input == nil {
input = &SendEmailInput{}
}
req := c.newRequest(op, input, &SendEmailOutput{})
return SendEmailRequest{Request: req, Input: input, Copy: c.SendEmailRequest}
}
// SendEmailRequest is the request type for the
// SendEmail API operation.
type SendEmailRequest struct {
*aws.Request
Input *SendEmailInput
Copy func(*SendEmailInput) SendEmailRequest
}
// Send marshals and sends the SendEmail API request.
func (r SendEmailRequest) Send(ctx context.Context) (*SendEmailResponse, error) {
r.Request.SetContext(ctx)
err := r.Request.Send()
if err != nil {
return nil, err
}
resp := &SendEmailResponse{
SendEmailOutput: r.Request.Data.(*SendEmailOutput),
response: &aws.Response{Request: r.Request},
}
return resp, nil
}
// SendEmailResponse is the response type for the
// SendEmail API operation.
type SendEmailResponse struct {
*SendEmailOutput
response *aws.Response
}
// SDKResponseMetdata returns the response metadata for the
// SendEmail request.
func (r *SendEmailResponse) SDKResponseMetdata() *aws.Response {
return r.response
}