From f75331b116a29d02623db666fe5e739ecbeb9178 Mon Sep 17 00:00:00 2001 From: Arpit Mohan Date: Thu, 19 Dec 2019 13:01:16 +0530 Subject: [PATCH] Adding a flag to determine if we should send emails for that particular environment --- .../server/configurations/EmailConfig.java | 16 ++++++++++++++++ .../server/notifications/EmailSender.java | 9 +++++++++ .../main/resources/application-docker.properties | 1 + .../main/resources/application-local.properties | 1 + .../resources/application-staging.properties | 1 + .../test/resources/application-test.properties | 1 + 6 files changed, 29 insertions(+) create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/EmailConfig.java diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/EmailConfig.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/EmailConfig.java new file mode 100644 index 0000000000..6a3de54a96 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/configurations/EmailConfig.java @@ -0,0 +1,16 @@ +package com.appsmith.server.configurations; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Getter +@Setter +@Configuration +public class EmailConfig { + + @Value("${mail.enabled}") + private boolean emailEnabled = true; + +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/notifications/EmailSender.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/notifications/EmailSender.java index 8c0e4e0dae..eceb7c620a 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/notifications/EmailSender.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/notifications/EmailSender.java @@ -1,5 +1,6 @@ package com.appsmith.server.notifications; +import com.appsmith.server.configurations.EmailConfig; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mail.SimpleMailMessage; @@ -13,9 +14,17 @@ public class EmailSender { @Autowired JavaMailSender emailSender; + @Autowired + EmailConfig emailConfig; + private final String MAIL_FROM = "hello@appsmith.com"; public void sendMail(String to, String subject, String text) { + // Don't send an email for local, dev or test environments + if(!emailConfig.isEmailEnabled()) { + return; + } + log.debug("Going to send email to {} with subject {}", to, subject); SimpleMailMessage message = new SimpleMailMessage(); diff --git a/app/server/appsmith-server/src/main/resources/application-docker.properties b/app/server/appsmith-server/src/main/resources/application-docker.properties index 398d8d24a8..358b77a056 100644 --- a/app/server/appsmith-server/src/main/resources/application-docker.properties +++ b/app/server/appsmith-server/src/main/resources/application-docker.properties @@ -36,6 +36,7 @@ acl.host=http://opa:8181/v1/data acl.package.name=/appsmith/authz/url_allow # Mail Properties +mail.enabled=true spring.mail.host=email-smtp.us-east-1.amazonaws.com spring.mail.port=587 spring.mail.username=AKIAVWHAAGIQOHPT4BZ7 diff --git a/app/server/appsmith-server/src/main/resources/application-local.properties b/app/server/appsmith-server/src/main/resources/application-local.properties index 303d3ff6bc..fe3801255d 100644 --- a/app/server/appsmith-server/src/main/resources/application-local.properties +++ b/app/server/appsmith-server/src/main/resources/application-local.properties @@ -36,6 +36,7 @@ acl.host=http://localhost:8181/v1/data acl.package.name=/appsmith/authz/url_allow # Mail Properties +mail.enabled=false spring.mail.host=email-smtp.us-east-1.amazonaws.com spring.mail.port=587 spring.mail.username=AKIAVWHAAGIQOHPT4BZ7 diff --git a/app/server/appsmith-server/src/main/resources/application-staging.properties b/app/server/appsmith-server/src/main/resources/application-staging.properties index 8a65f869d1..9b2f51bdcd 100644 --- a/app/server/appsmith-server/src/main/resources/application-staging.properties +++ b/app/server/appsmith-server/src/main/resources/application-staging.properties @@ -35,6 +35,7 @@ acl.host=https://openpolicyagent.herokuapp.com/v1/data acl.package.name=/appsmith/authz/url_allow # Mail Properties +mail.enabled=true spring.mail.host=email-smtp.us-east-1.amazonaws.com spring.mail.port=587 spring.mail.username=AKIAVWHAAGIQOHPT4BZ7 diff --git a/app/server/appsmith-server/src/test/resources/application-test.properties b/app/server/appsmith-server/src/test/resources/application-test.properties index 6ee595e68f..0f3fde00b4 100644 --- a/app/server/appsmith-server/src/test/resources/application-test.properties +++ b/app/server/appsmith-server/src/test/resources/application-test.properties @@ -33,6 +33,7 @@ acl.package.name=/appsmith/authz/url_allow # Mail Properties +mail.enabled=false spring.mail.host=email-smtp.us-east-1.amazonaws.com spring.mail.port=587 spring.mail.username=AKIAVWHAAGIQOHPT4BZ7