Skip to content

Commit 4e7074d

Browse files
authored
Merge pull request #351 from miqe/feat/add_sender_name
Feat/add sender name
2 parents f291417 + bdfa045 commit 4e7074d

File tree

12 files changed

+111
-2
lines changed

12 files changed

+111
-2
lines changed

.env.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ SMTP_PORT=2525
77
SMTP_USERNAME=test
88
SMTP_PASSWORD=test
99
SENDER_EMAIL="[email protected]"
10+
SENDER_NAME="Authorizer"
1011
AWS_REGION=ap-south-1

dashboard/src/components/EnvComponents/EmailConfiguration.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ const EmailConfigurations = ({
126126
/>
127127
</Center>
128128
</Flex>
129+
<Flex direction={isNotSmallerScreen ? 'row' : 'column'}>
130+
<Flex w="30%" justifyContent="start" alignItems="center">
131+
<Text fontSize="sm">Sender Name:</Text>
132+
</Flex>
133+
<Center
134+
w={isNotSmallerScreen ? '70%' : '100%'}
135+
mt={isNotSmallerScreen ? '0' : '3'}
136+
>
137+
<InputField
138+
borderRadius={5}
139+
variables={variables}
140+
setVariables={setVariables}
141+
inputType={TextInputType.SENDER_NAME}
142+
/>
143+
</Center>
144+
</Flex>
129145
</Stack>
130146
</div>
131147
);

dashboard/src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const TextInputType = {
1919
SMTP_USERNAME: 'SMTP_USERNAME',
2020
SMTP_LOCAL_NAME: 'SMTP_LOCAL_NAME',
2121
SENDER_EMAIL: 'SENDER_EMAIL',
22+
SENDER_NAME: 'SENDER_NAME',
2223
ORGANIZATION_NAME: 'ORGANIZATION_NAME',
2324
ORGANIZATION_LOGO: 'ORGANIZATION_LOGO',
2425
DATABASE_NAME: 'DATABASE_NAME',
@@ -143,6 +144,7 @@ export interface envVarTypes {
143144
SMTP_PASSWORD: string;
144145
SMTP_LOCAL_NAME: string;
145146
SENDER_EMAIL: string;
147+
SENDER_NAME: string;
146148
ALLOWED_ORIGINS: [string] | [];
147149
ORGANIZATION_NAME: string;
148150
ORGANIZATION_LOGO: string;

dashboard/src/graphql/queries/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export const EnvVariablesQuery = `
5050
SMTP_PASSWORD
5151
SMTP_LOCAL_NAME
5252
SENDER_EMAIL
53+
SENDER_NAME
5354
ALLOWED_ORIGINS
5455
ORGANIZATION_NAME
5556
ORGANIZATION_LOGO

dashboard/src/pages/Environment.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const Environment = () => {
7070
SMTP_PASSWORD: '',
7171
SMTP_LOCAL_NAME: '',
7272
SENDER_EMAIL: '',
73+
SENDER_NAME: '',
7374
ALLOWED_ORIGINS: [],
7475
ORGANIZATION_NAME: '',
7576
ORGANIZATION_LOGO: '',

server/constants/env.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ const (
6262
EnvKeySmtpLocalName = "SMTP_LOCAL_NAME"
6363
// EnvKeySenderEmail key for env variable SENDER_EMAIL
6464
EnvKeySenderEmail = "SENDER_EMAIL"
65+
// EnvKeySenderName key for env variable SENDER_NAME
66+
EnvKeySenderName = "SENDER_NAME"
6567
// EnvKeyIsEmailServiceEnabled key for env variable IS_EMAIL_SERVICE_ENABLED
6668
EnvKeyIsEmailServiceEnabled = "IS_EMAIL_SERVICE_ENABLED"
6769
// EnvKeyAppCookieSecure key for env variable APP_COOKIE_SECURE

server/email/email.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ func SendEmail(to []string, event string, data map[string]interface{}) error {
103103
return err
104104
}
105105

106+
senderName, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeySenderName)
107+
if err != nil {
108+
log.Errorf("Error while getting sender name from env variable: %v", err)
109+
return err
110+
}
111+
106112
smtpPort, err := memorystore.Provider.GetStringStoreEnvVariable(constants.EnvKeySmtpPort)
107113
if err != nil {
108114
log.Errorf("Error while getting smtp port from env variable: %v", err)
@@ -139,7 +145,7 @@ func SendEmail(to []string, event string, data map[string]interface{}) error {
139145
return err
140146
}
141147

142-
m.SetHeader("From", senderEmail)
148+
m.SetAddressHeader("From", senderEmail, senderName)
143149
m.SetHeader("To", to...)
144150
m.SetHeader("Subject", tmp.Subject)
145151
m.SetBody("text/html", tmp.Template)

server/env/env.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func InitAllEnv() error {
5757
osSmtpPassword := os.Getenv(constants.EnvKeySmtpPassword)
5858
osSmtpLocalName := os.Getenv(constants.EnvKeySmtpLocalName)
5959
osSenderEmail := os.Getenv(constants.EnvKeySenderEmail)
60+
osSenderName := os.Getenv(constants.EnvKeySenderName)
6061
osJwtType := os.Getenv(constants.EnvKeyJwtType)
6162
osJwtSecret := os.Getenv(constants.EnvKeyJwtSecret)
6263
osJwtPrivateKey := os.Getenv(constants.EnvKeyJwtPrivateKey)
@@ -257,6 +258,13 @@ func InitAllEnv() error {
257258
envData[constants.EnvKeySenderEmail] = osSenderEmail
258259
}
259260

261+
if val, ok := envData[constants.EnvKeySenderName]; !ok || val == "" {
262+
envData[constants.EnvKeySenderName] = osSenderName
263+
}
264+
if osSenderName != "" && envData[constants.EnvKeySenderName] != osSenderName {
265+
envData[constants.EnvKeySenderName] = osSenderName
266+
}
267+
260268
algoVal, ok := envData[constants.EnvKeyJwtType]
261269
algo := ""
262270
if !ok || algoVal == "" {

server/graph/generated/generated.go

Lines changed: 66 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/graph/model/models_gen.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)