Select Git revision
ses.go 5.99 KiB
package ses
import (
"bytes"
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ses"
sesTypes "github.com/aws/aws-sdk-go-v2/service/ses/types"
"github.com/prozz/aws-embedded-metrics-golang/emf"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/errors"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/logs"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/s3"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/utils"
"gopkg.in/gomail.v2"
"io"
"strings"
)
const (
InvalidParameterValueErrorString = "InvalidParameterValue"
)
var (
clients = map[string]*ClientWithHelpers{}
ErrorSESClientNotEstablished = errors.Error("could not establish an SES client")
)
type ClientWithHelpers struct {
SESClient *ses.Client
}
type Email struct {
Recipient string `json:"recipient"`
FromName string `json:"from_name"`
FromEmail string `json:"from_email"`
Subject string `json:"subject"`
EmailCcName string `json:"email_cc_name"`
EmailCcAddress string `json:"email_cc_address"`
ReplyToEmailAddress string `json:"reply_to_email_address"`
Body EmailBody `json:"body"`
Attachments *[]s3.S3UploadResponse `json:"attachments"`
}
type EmailBody struct {
HTMLBody string `json:"html_body"`
TextBody string `json:"text_body"`
}
func GetClient(region ...string) *ClientWithHelpers {
sesRegion := "eu-west-1"
// Set custom region
if region != nil && len(region) > 0 {
sesRegion = region[0]
}
// Check if client exists for region, if it does return it
if sesClient, ok := clients[sesRegion]; ok && sesClient != nil {
return sesClient
}
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion(sesRegion),
)
if err != nil {
return &ClientWithHelpers{}
}