Skip to content

Commit

Permalink
Merge pull request #351 from miqe/feat/add_sender_name
Browse files Browse the repository at this point in the history
Feat/add sender name
  • Loading branch information
lakhansamani authored May 16, 2023
2 parents f291417 + bdfa045 commit 4e7074d
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ SMTP_PORT=2525
SMTP_USERNAME=test
SMTP_PASSWORD=test
SENDER_EMAIL="[email protected]"
SENDER_NAME="Authorizer"
AWS_REGION=ap-south-1
16 changes: 16 additions & 0 deletions dashboard/src/components/EnvComponents/EmailConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ const EmailConfigurations = ({
/>
</Center>
</Flex>
<Flex direction={isNotSmallerScreen ? 'row' : 'column'}>
<Flex w="30%" justifyContent="start" alignItems="center">
<Text fontSize="sm">Sender Name:</Text>
</Flex>
<Center
w={isNotSmallerScreen ? '70%' : '100%'}
mt={isNotSmallerScreen ? '0' : '3'}
>
<InputField
borderRadius={5}
variables={variables}
setVariables={setVariables}
inputType={TextInputType.SENDER_NAME}
/>
</Center>
</Flex>
</Stack>
</div>
);
Expand Down
2 changes: 2 additions & 0 deletions dashboard/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const TextInputType = {
SMTP_USERNAME: 'SMTP_USERNAME',
SMTP_LOCAL_NAME: 'SMTP_LOCAL_NAME',
SENDER_EMAIL: 'SENDER_EMAIL',
SENDER_NAME: 'SENDER_NAME',
ORGANIZATION_NAME: 'ORGANIZATION_NAME',
ORGANIZATION_LOGO: 'ORGANIZATION_LOGO',
DATABASE_NAME: 'DATABASE_NAME',
Expand Down Expand Up @@ -143,6 +144,7 @@ export interface envVarTypes {
SMTP_PASSWORD: string;
SMTP_LOCAL_NAME: string;
SENDER_EMAIL: string;
SENDER_NAME: string;
ALLOWED_ORIGINS: [string] | [];
ORGANIZATION_NAME: string;
ORGANIZATION_LOGO: string;
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/graphql/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const EnvVariablesQuery = `
SMTP_PASSWORD
SMTP_LOCAL_NAME
SENDER_EMAIL
SENDER_NAME
ALLOWED_ORIGINS
ORGANIZATION_NAME
ORGANIZATION_LOGO
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/pages/Environment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const Environment = () => {
SMTP_PASSWORD: '',
SMTP_LOCAL_NAME: '',
SENDER_EMAIL: '',
SENDER_NAME: '',
ALLOWED_ORIGINS: [],
ORGANIZATION_NAME: '',
ORGANIZATION_LOGO: '',
Expand Down
2 changes: 2 additions & 0 deletions server/constants/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const (
EnvKeySmtpLocalName = "SMTP_LOCAL_NAME"
// EnvKeySenderEmail key for env variable SENDER_EMAIL
EnvKeySenderEmail = "SENDER_EMAIL"
// EnvKeySenderName key for env variable SENDER_NAME
EnvKeySenderName = "SENDER_NAME"
// EnvKeyIsEmailServiceEnabled key for env variable IS_EMAIL_SERVICE_ENABLED
EnvKeyIsEmailServiceEnabled = "IS_EMAIL_SERVICE_ENABLED"
// EnvKeyAppCookieSecure key for env variable APP_COOKIE_SECURE
Expand Down
8 changes: 7 additions & 1 deletion server/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ func SendEmail(to []string, event string, data map[string]interface{}) error {
return err
}

senderName, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeySenderName)
if err != nil {
log.Errorf("Error while getting sender name from env variable: %v", err)
return err
}

smtpPort, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeySmtpPort)
if err != nil {
log.Errorf("Error while getting smtp port from env variable: %v", err)
Expand Down Expand Up @@ -139,7 +145,7 @@ func SendEmail(to []string, event string, data map[string]interface{}) error {
return err
}

m.SetHeader("From", senderEmail)
m.SetAddressHeader("From", senderEmail, senderName)
m.SetHeader("To", to...)
m.SetHeader("Subject", tmp.Subject)
m.SetBody("text/html", tmp.Template)
Expand Down
8 changes: 8 additions & 0 deletions server/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func InitAllEnv() error {
osSmtpPassword := os.Getenv(constants.EnvKeySmtpPassword)
osSmtpLocalName := os.Getenv(constants.EnvKeySmtpLocalName)
osSenderEmail := os.Getenv(constants.EnvKeySenderEmail)
osSenderName := os.Getenv(constants.EnvKeySenderName)
osJwtType := os.Getenv(constants.EnvKeyJwtType)
osJwtSecret := os.Getenv(constants.EnvKeyJwtSecret)
osJwtPrivateKey := os.Getenv(constants.EnvKeyJwtPrivateKey)
Expand Down Expand Up @@ -257,6 +258,13 @@ func InitAllEnv() error {
envData[constants.EnvKeySenderEmail] = osSenderEmail
}

if val, ok := envData[constants.EnvKeySenderName]; !ok || val == "" {
envData[constants.EnvKeySenderName] = osSenderName
}
if osSenderName != "" && envData[constants.EnvKeySenderName] != osSenderName {
envData[constants.EnvKeySenderName] = osSenderName
}

algoVal, ok := envData[constants.EnvKeyJwtType]
algo := ""
if !ok || algoVal == "" {
Expand Down
67 changes: 66 additions & 1 deletion server/graph/generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type Env {
SMTP_PASSWORD: String
SMTP_LOCAL_NAME: String
SENDER_EMAIL: String
SENDER_NAME: String
JWT_TYPE: String
JWT_SECRET: String
JWT_PRIVATE_KEY: String
Expand Down Expand Up @@ -235,6 +236,7 @@ input UpdateEnvInput {
SMTP_PASSWORD: String
SMTP_LOCAL_NAME: String
SENDER_EMAIL: String
SENDER_NAME: String
JWT_TYPE: String
JWT_SECRET: String
JWT_PRIVATE_KEY: String
Expand Down
3 changes: 3 additions & 0 deletions server/resolvers/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func EnvResolver(ctx context.Context) (*model.Env, error) {
if val, ok := store[constants.EnvKeySenderEmail]; ok {
res.SenderEmail = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeySenderName]; ok {
res.SenderName = refs.NewStringRef(val.(string))
}
if val, ok := store[constants.EnvKeySmtpLocalName]; ok {
res.SMTPLocalName = refs.NewStringRef(val.(string))
}
Expand Down

0 comments on commit 4e7074d

Please sign in to comment.