This repository was archived by the owner on May 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaws_ses.go
More file actions
90 lines (74 loc) · 1.78 KB
/
Copy pathaws_ses.go
File metadata and controls
90 lines (74 loc) · 1.78 KB
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
package mail
import (
"encoding/json"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ses"
"github.com/dominik-zeglen/inkster/config"
)
type AwsSesMailer struct {
awsSes *ses.SES
sender string
}
func NewAwsSesMailer(config config.Config) AwsSesMailer {
awsConfig := aws.Config{
Region: &config.AWS.Region,
}
awsConfig.Credentials = credentials.NewStaticCredentials(
config.AWS.AccessKey,
config.AWS.SecretAccessKey,
"",
)
awsSession, err := session.NewSession(&awsConfig)
if err != nil {
panic(err)
}
awsSes := ses.New(awsSession)
return AwsSesMailer{
awsSes: awsSes,
sender: config.Mail.Sender,
}
}
func (mailer AwsSesMailer) SendPasswordResetToken(
recipient string,
data SendPasswordResetTokenTemplateData,
) error {
templateData, err := json.Marshal(data)
if err != nil {
return err
}
input := &ses.SendTemplatedEmailInput{
Destination: &ses.Destination{
ToAddresses: []*string{
aws.String(recipient),
},
},
Template: aws.String("ResetPassword"),
TemplateData: aws.String(string(templateData)),
Source: aws.String(mailer.sender),
}
_, err = mailer.awsSes.SendTemplatedEmail(input)
return err
}
func (mailer AwsSesMailer) SendUserInvitation(
recipient string,
data SendUserInvitationTemplateData,
) error {
templateData, err := json.Marshal(data)
if err != nil {
return err
}
input := &ses.SendTemplatedEmailInput{
Destination: &ses.Destination{
ToAddresses: []*string{
aws.String(recipient),
},
},
Template: aws.String("UserInvitation"),
TemplateData: aws.String(string(templateData)),
Source: aws.String(mailer.sender),
}
_, err = mailer.awsSes.SendTemplatedEmail(input)
return err
}