diff --git a/internal/config/server/config.go b/internal/config/server/config.go index 1f761f4ca1..7f311eaeff 100644 --- a/internal/config/server/config.go +++ b/internal/config/server/config.go @@ -47,6 +47,7 @@ type Config struct { Marketplace MarketplaceConfig `mapstructure:"marketplace"` DefaultProfiles DefaultProfilesConfig `mapstructure:"default_profiles"` Crypto CryptoConfig `mapstructure:"crypto"` + Email EmailConfig `mapstructure:"email"` } // DefaultConfigForTest returns a configuration with all the struct defaults set, diff --git a/internal/config/server/email.go b/internal/config/server/email.go new file mode 100644 index 0000000000..584ec285ef --- /dev/null +++ b/internal/config/server/email.go @@ -0,0 +1,15 @@ +package server + +// EmailConfig is the configuration for the email sending service +type EmailConfig struct { + // AWSSES is the AWS SES configuration + AWSSES AWSSES `mapstructure:"aws_ses"` +} + +// AWSSES is the AWS SES configuration +type AWSSES struct { + // Sender is the email address of the sender + Sender string `mapstructure:"sender"` + // Region is the AWS region to use for AWS SES + Region string `mapstructure:"region"` +} diff --git a/internal/email/awsses.go b/internal/email/awsses.go index acfbca2d35..4bda7f7f98 100644 --- a/internal/email/awsses.go +++ b/internal/email/awsses.go @@ -25,10 +25,12 @@ import ( ) const ( - // awsUSEast1 is the AWS region - awsUSEast1 = "us-east-1" // CharSet is the character set for the email CharSet = "UTF-8" + // DefaultAWSRegion is the default AWS region + DefaultAWSRegion = "us-east-1" + // DefaultSender is the default sender email address + DefaultSender = "noreply@stacklok.com" ) // AWSSES is the AWS SES client @@ -38,10 +40,18 @@ type AWSSES struct { } // NewAWSSES creates a new AWS SES client -func NewAWSSES(sender string) (*AWSSES, error) { +func NewAWSSES(sender, region string) (*AWSSES, error) { + // Set the sender and region in case they are not provided. + if sender == "" { + sender = DefaultSender + } + if region == "" { + region = DefaultAWSRegion + } + // Create a new session. sess, err := session.NewSession(&aws.Config{ - Region: aws.String(awsUSEast1)}, + Region: aws.String(region)}, ) if err != nil { return nil, err diff --git a/internal/service/service.go b/internal/service/service.go index 15f4db248f..aa58dcf863 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -209,8 +209,7 @@ func AllInOneServerService( evt.ConsumeEvents(im) // Register the email manager to handle email invitations - // TODO: This should be read from the config - mailClient, err := email.NewAWSSES("noreply@stacklok.com") + mailClient, err := email.NewAWSSES(cfg.Email.AWSSES.Sender, cfg.Email.AWSSES.Region) if err != nil { return fmt.Errorf("unable to create email client: %w", err) }