-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get email sender and region from config
Signed-off-by: Radoslav Dimitrov <[email protected]>
- Loading branch information
Showing
4 changed files
with
31 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = "[email protected]" | ||
) | ||
|
||
// 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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("[email protected]") | ||
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) | ||
} | ||
|