-
Notifications
You must be signed in to change notification settings - Fork 0
/
ses.go
66 lines (55 loc) · 1.28 KB
/
ses.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
package notify
import (
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ses"
"github.com/aws/aws-sdk-go/service/ses/sesiface"
)
var _ Notifier = &sesService{}
type sesService struct {
client sesiface.SESAPI
}
// NewSESService returns a new sesService instance.
func NewSESService(svc sesiface.SESAPI) Notifier {
return &sesService{
client: svc,
}
}
// Notify implements the SES behavior of posting a message.
func (s *sesService) Notify(params interface{}) error {
sesParams := params.(*SESNotifyInput)
input := &ses.SendEmailInput{
Destination: &ses.Destination{
ToAddresses: aws.StringSlice(sesParams.To),
},
Message: &ses.Message{
Body: &ses.Body{
Text: &ses.Content{
Data: &sesParams.Message,
Charset: aws.String("utf-8"),
},
},
Subject: &ses.Content{
Data: &sesParams.Subject,
Charset: aws.String("utf-8"),
},
},
Source: aws.String(sesParams.From),
}
resp, err := s.client.SendEmail(input)
if err != nil {
return err
}
if sesParams.Debug {
log.Printf("message sent on aws ses: %v", resp.MessageId)
}
return nil
}
// SESNotifyInput stores the input parameters to send notification.
type SESNotifyInput struct {
From string
Message string
To []string
Subject string
Debug bool
}