package mail import ( "context" "github.com/aws/aws-sdk-go-v2/aws" awsconfig "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/sesv2" sesv2types "github.com/aws/aws-sdk-go-v2/service/sesv2/types" ) // EmailSender is the one SESv2 call the console makes to send as itself // (its invite fallback), narrowed so tests use a fake. Apps never use it: // they send by SMTP with their own credential. type EmailSender interface { SendEmail(context.Context, *sesv2.SendEmailInput, ...func(*sesv2.Options)) (*sesv2.SendEmailOutput, error) } // NewSESEmailSender builds a sender on the default credential chain, which // on a box is the host role. func NewSESEmailSender(ctx context.Context, region string) (EmailSender, error) { cfg, err := awsconfig.LoadDefaultConfig(ctx, awsconfig.WithRegion(region)) if err != nil { return nil, err } return sesv2.NewFromConfig(cfg), nil } // SimpleEmailInput is a plain-text message attributed to tenant and, when // set, counted through configSet. func SimpleEmailInput(from, to, subject, body, tenant, configSet string) *sesv2.SendEmailInput { in := &sesv2.SendEmailInput{ FromEmailAddress: aws.String(from), Destination: &sesv2types.Destination{ToAddresses: []string{to}}, Content: &sesv2types.EmailContent{Simple: &sesv2types.Message{ Subject: &sesv2types.Content{Data: aws.String(subject), Charset: aws.String("UTF-8")}, Body: &sesv2types.Body{Text: &sesv2types.Content{Data: aws.String(body), Charset: aws.String("UTF-8")}}, }}, TenantName: aws.String(tenant), } if configSet != "" { in.ConfigurationSetName = aws.String(configSet) } return in }