|
1
|
|
|
package ses |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"context" |
|
5
|
|
|
|
|
6
|
|
|
"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors" |
|
7
|
|
|
) |
|
8
|
|
|
|
|
9
|
|
|
// XCreateTemplate creates an email template. |
|
10
|
|
|
func (svc *SES) XCreateTemplate(ctx context.Context, templateName, subject, htmlBody, textBody string) error { |
|
11
|
|
|
_, err := svc.CreateTemplate(ctx, CreateTemplateRequest{ |
|
12
|
|
|
Template: Template{ |
|
13
|
|
|
TemplateName: templateName, |
|
14
|
|
|
SubjectPart: subject, |
|
15
|
|
|
HTMLPart: htmlBody, |
|
16
|
|
|
TextPart: textBody, |
|
17
|
|
|
}, |
|
18
|
|
|
}) |
|
19
|
|
|
return err |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
// XGetTemplate gets an email template. |
|
23
|
|
|
func (svc *SES) XGetTemplate(ctx context.Context, templateName string) (*GetTemplateResult, error) { |
|
24
|
|
|
return svc.GetTemplate(ctx, GetTemplateRequest{ |
|
25
|
|
|
TemplateName: templateName, |
|
26
|
|
|
}) |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
// XExistsTemplate checks if the template already exists or not. |
|
30
|
|
|
func (svc *SES) XExistsTemplate(ctx context.Context, templateName string) (bool, error) { |
|
31
|
|
|
_, err := svc.GetTemplate(ctx, GetTemplateRequest{ |
|
32
|
|
|
TemplateName: templateName, |
|
33
|
|
|
}) |
|
34
|
|
|
|
|
35
|
|
|
if e, ok := err.(errors.ErrorData); ok { |
|
36
|
|
|
if e.GetAWSErrCode() == "TemplateDoesNotExist" { |
|
37
|
|
|
return false, nil |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
if err != nil { |
|
41
|
|
|
return false, err |
|
42
|
|
|
} |
|
43
|
|
|
return true, nil |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// XUpdateTemplate updates an email template. |
|
47
|
|
|
func (svc *SES) XUpdateTemplate(ctx context.Context, templateName, subject, htmlBody, textBody string) error { |
|
48
|
|
|
_, err := svc.UpdateTemplate(ctx, UpdateTemplateRequest{ |
|
49
|
|
|
Template: Template{ |
|
50
|
|
|
TemplateName: templateName, |
|
51
|
|
|
SubjectPart: subject, |
|
52
|
|
|
HTMLPart: htmlBody, |
|
53
|
|
|
TextPart: textBody, |
|
54
|
|
|
}, |
|
55
|
|
|
}) |
|
56
|
|
|
return err |
|
57
|
|
|
} |
|
58
|
|
|
|